Question 1
What is displayed as a result of running the code segment?pets ← ["cat", "dog", "fish",
"dog", "bird"]
pos ← 0
i ← 1
FOR EACH p IN pets
{
IF (p = "dog")
{
pos ← i
}
i ← i + 1
}
DISPLAY(pos)
Computer Science Principles Exam Prep
The exam writes code in its own pseudocode, and a reference sheet is provided. Lists start at index 1, and REPEAT UNTIL stops when its condition becomes true.
| Assignment | a ← expression |
|---|---|
| Lists | Indexed from 1; an index outside the list is an error |
| Division | 17 / 5 is 3.4; 17 MOD 5 is 2 |
Yes. It shows the exam's pseudocode for assignment, display, arithmetic, conditions, loops, lists, procedures and the robot.
From 1. The first item of aList is aList[1].