ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Iteration/Nested loops
J277 · 2.2.1

Unit 7 · Lesson 6

Nested loops

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Trace and write nested loops, explaining how often the inner body executes.

In a nested loop, the inner loop completes all its iterations for every one iteration of the outer loop. Three rows and four columns therefore create 3 × 4 = 12 combinations. Keep the inner loop indented and close ERL loops in the reverse order that they opened.

Nested loop

A loop placed inside another loop.

Outer loop

The enclosing loop that starts a new complete run of the inner loop.

Inner loop

The enclosed loop that completes for each outer-loop iteration.

Combination

One pairing of an outer-loop value with an inner-loop value.

Keep these in mind

  • The inner loop restarts for every new outer-loop value.
  • Multiply iteration counts to find how often the inner body runs.
  • Python indentation shows which loop contains the inner body.
  • ERL closes the inner next before the outer next.

Learning objective

Trace and write nested loops, explaining how often the inner body executes.

Exam tip

When tracing, hold one outer value still and work through every inner value before advancing the outer loop.

Common mistake

Closing next row before next column breaks the nesting. The last loop opened is the first loop closed.

PreviousNext