ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Strings & arrays/Looping through 1D arrays
J277 · 2.2.3

Unit 8 · Lesson 5

Looping through 1D arrays

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Traverse every 1D array element with correct ERL and Python loop bounds.

To visit every array element, use the loop counter as its index. ERL loops from 0 to array.length - 1 because to is inclusive. Python range(len(array)) naturally produces the same valid indices. Starting at 1 misses the first element; ending at length goes out of bounds.

Traversal

Visiting each item in a data structure in a systematic order.

Loop counter

The changing for-loop variable that can be used as an array index.

Linear search

Checking array values one by one in order until a target is found or the list ends.

Off-by-one error

Starting or ending a traversal one index too early or too late.

Keep these in mind

  • Use the same counter name inside the indexed expression.
  • ERL traversal is 0 to length - 1.
  • Python traversal by index is range(len(array)).
  • A Python loop written for item in values gives item values, not indices.

Learning objective

Traverse every 1D array element with correct ERL and Python loop bounds.

Exam tip

If the counter is called count, access theTeam[count]. Do not switch to a different undeclared index name.

Common mistake

In Python for x in values, x is an item value. Writing values[x] afterwards incorrectly treats that value as an index.

PreviousNext