Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1IF Found = TRUE THEN OUTPUT "Found at ", Index ENDIF | AOutputs the position of the target, but only when the search loop has found it | |
| 2ELSE OUTPUT "Not found" | BThe IF…ELSE on Found is inside the loop, so it outputs a result on every pass. It should come after NEXT Index, once the search is finished. | |
| 3If the target is the first item, the search loop finds it on its first pass, so Found is TRUE and Index is 1 for the output | CRuns when the Found flag is still FALSE, so the target is missing from the array | |
| 4If the target is missing, the loop ends without changing Found, so the ELSE branch outputs a not-found message | DThe two outputs are the wrong way round. TRUE should output Found at with the Index, and ELSE should output Not found. | |
| 5FOR Index ← 1 TO 10 IF List[Index] = Target THEN Found ← TRUE ENDIF IF Found = TRUE THEN OUTPUT "Found at ", Index ELSE OUTPUT "Not found" ENDIF NEXT Index | EIF Found = FALSE THEN OUTPUT "Not found" ENDIF | |
| 6IF Found = TRUE THEN OUTPUT "Not found" ELSE OUTPUT "Found at ", Index ENDIF | FFound ← TRUE Index ← 1 OUTPUT "Found at ", Index |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
IF Found = TRUE THEN OUTPUT "Found at ", Index ELSE OUTPUT "Not found" ENDIF — After the search loop, check the Found flag: if TRUE, output the position (Index) where the target was found, otherwise output a not-found message. Covers first, last and missing items.IF Found = TRUE THEN
OUTPUT "Found at ", Index
ELSEIF Found = TRUE THEN
OUTPUT "Found at ", Index
ELSEIF Found = TRUE THEN
OUTPUT "Found at ", Index
ELSEELSE
OUTPUT "Not found"
ENDIFELSE
OUTPUT "Not found"
ENDIF