while Loops

AP Computer Science A· difficulty 3/5

<code>while</code> is often preferred over <code>for</code> when

  • A

    Counting up by 1

  • B

    Number of iterations is known

  • C

    Number of iterations is unknown (loop while a condition holds)

    check_circle
  • D

    Iterating an array

Explanation

<code>for</code> excels at counted loops; <code>while</code> for condition-driven loops.

Want 10 more like this — adaptive to your weak spots?

Related questions