Apply · Trace · Pseudocode · Efficiency
found = FALSE — the flag. Set before the loop. Flips to TRUE when the target is found.FOR i = 0 TO LEN(data)-1 — visits every index. LEN gives the number of elements.data[i] == target — the comparison. Square brackets for array access.| i | data[i] | == target? | found | OUTPUT |
|---|---|---|---|---|
| 0 | 5 | FALSE | FALSE | |
| 1 | 2 | FALSE | ||
| 2 | 8 | TRUE | TRUE | 2 |
| 3 | 1 | FALSE | ||
| 4 | 9 | FALSE |
| i | data[i] | == target? | found | OUTPUT |
|---|---|---|---|---|
| 0 | 5 | FALSE | FALSE | |
| 1 | 2 | FALSE | ||
| 2 | 8 | FALSE | ||
| 3 | 1 | FALSE | ||
| 4 | 9 | FALSE | ||
| Loop ends — found still FALSE → trigger final IF | "Not found" | |||
data[i]) to the target value.found) initialised to FALSE before the loop, set to TRUE when the target is located.Next up: 2.1.3b — Binary Search