Trace Lab
csguided.co.uk
GCSE (J277)

Linear Search and Index Match

A FOR loop checks each item of a 1D array against a target.

OCR Exam Reference Language
1names = ["Ali", "Beth", "Cara", "Dev"]◀ now
2target = "Cara"
3found = -1
4FOR i = 0 TO 3
5 IF names[i]! == target THEN
6 found = i
7 ENDIF
8NEXT i
9print(found)
Predict
Line 1Step 1 of 13
The array names is created with indexes 0 to 3
Nothing to predict here. Press Step and Predict to run this line.
OCR Trace Table0 rows
LinenamestargetfoundiConditionOutput
Rows appear here as you solve each line.