Mathematics I / Loops and Iteration
Practice question · Put in order

Order what a loop does, from entry to the start of its second pass.

Hints
  1. A while loop checks its condition BEFORE each pass, not after.
  2. The update is the last thing a pass does; without it the same test is repeated forever.
Show the answer
  1. Initialise the counter
  2. Test the condition
  3. Run the loop body
  4. Update the counter
  5. Test the condition again
Why

Initialisation, condition, body, update, condition, the three ingredients in their natural cycle. If the update is missing or moves the wrong way, the second test gives the same verdict as the first and the loop never ends.

Read the lesson: Loops and Iteration →

Practise Loops and Iteration

The app has 6 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.

More questions on Loops and Iteration