Emily is writing a function to calculate the factorial of a number using a loop. Which loop structure would be the most appropriate for this task?

  • Do-While Loop
  • For Loop
  • Switch Statement
  • While Loop
Emily should use a For Loop to calculate the factorial of a number. A For Loop is well-suited for tasks where you know in advance how many iterations are required, as is the case with factorial calculations. She can initialize the loop variable, set the loop condition to run until the variable reaches 1, and decrement the variable in each iteration to multiply the numbers in a descending order.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *