201k views
4 votes
We use FOR loops instead of WHILE loops when:

A) The number of iterations is known in advance.
B) The loop condition involves a range or sequence.
C) The loop body should execute at least once.
D) The loop is intended for indefinite repetition.

1 Answer

4 votes

Final answer:

We use FOR loops instead of WHILE loops when the number of iterations is known in advance or the loop condition involves a range or sequence.

Step-by-step explanation:

We use FOR loops instead of WHILE loops when:

  1. The number of iterations is known in advance.
  2. The loop condition involves a range or sequence.

FOR loops are often used when we want to repeat a certain block of code a specific number of times. They are particularly useful when we have a known range or sequence of values that we need to iterate over, such as iterating over an array or a list of items. In contrast, WHILE loops are commonly used when we want to repeat a block of code until a certain condition is no longer true.

User AntonyG
by
8.0k points