ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Iteration/For loops
J277 · 2.2.1

Unit 7 · Lesson 1

For loops

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Trace and write count-controlled loops with equivalent ERL and Python bounds.

Use a for loop when the number of repetitions is known. OCR ERL includes both values written after for and to. Python range() excludes its stop value, so ERL 0 to 4 becomes Python range(5). The loop variable takes each value in turn before the body runs.

Iteration

Repeating a set of instructions.

Count-controlled loop

A loop that repeats a known number of times.

Loop variable

A variable whose value changes automatically for each pass through a for loop.

range()

A Python function that produces the values used by a for loop; its stop value is excluded.

Keep these in mind

  • ERL closes a for loop with next followed by the loop variable.
  • The final value after ERL to is included.
  • The stop value supplied to Python range() is excluded.
  • Indented Python instructions form the repeated loop body.

Learning objective

Trace and write count-controlled loops with equivalent ERL and Python bounds.

Exam tip

Translate the values, not just the keywords. ERL for i=0 to 4 has five iterations, so its Python equivalent is range(5).

Common mistake

range(1, 5) produces 1, 2, 3 and 4. It does not include 5.

PreviousNext