ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Iteration/While loops
J277 · 2.2.1

Unit 7 · Lesson 3

While loops

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Trace and write pre-test condition-controlled loops that terminate correctly.

A while loop checks its condition before every iteration. If the condition starts false, the body runs zero times. Use while when the number of repetitions is not known in advance, and make sure something inside the loop can eventually make the condition false.

Condition-controlled loop

A loop whose repetition is controlled by a Boolean condition.

while loop

A pre-test loop that repeats while its condition is true.

Pre-test

Checking a condition before executing the loop body.

Infinite loop

A loop that never reaches a false stopping condition.

Keep these in mind

  • ERL closes a while loop with endwhile.
  • Python uses a colon and indentation instead of an ending keyword.
  • The condition is checked before the first iteration.
  • A value used by the condition normally needs updating inside the body.

Learning objective

Trace and write pre-test condition-controlled loops that terminate correctly.

Exam tip

Trace the condition before entering the loop and again after every update. The loop stops as soon as the condition becomes false.

Common mistake

Forgetting to change the condition variable creates an infinite loop. Repeated input or a numeric update must be inside the loop body.

PreviousNext