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 that involve iterating a specific number of times, such as calculating the factorial of a number, where she can easily control the loop's start, end, and iteration conditions. She can iterate through the numbers from 1 to the given number, multiplying them together to calculate the factorial.
Add your answer
Loading...

Leave a comment

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