KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Which of the following statements is most appropriate to illustrate the difference between a for loop and a while loop?

  1. A for loop is used for fixed iterations, while a while loop is used for conditional statements.
  2. A for loop is more concise than a while loop.
  3. There is no difference between for loop and while loop.
  4. They are not interchangeable.

Python Control Flow

1 Like

Answer

A for loop is used for fixed iterations, while a while loop is used for conditional statements.

Reason — The for loop is a fixed iterative loop where the number of iterations are known in advance. The while loop is an unfixed iterative loop which executes based on a conditional expression and continues until the condition becomes false.

Answered By

1 Like


Related Questions