Unit 3 · Programming 2 · Lesson 3.19

Pseudocode Gym II

A full workout reading exam-style AP Pseudocode — procedures, lists, loops, and random, all at once — plus your first look at the Robot grid questions the exam loves. Trace, predict, verify.

Big Idea 3 — Algorithms & ProgrammingReading fluency · Robot intro

Before this lesson

No new reading — this is a gym. Everything here is from Units 2–3. The one new thing is the Robot notation, introduced below; its full treatment comes in Unit 4.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

Still in Programs, one day before the test. The exam writes most code in AP Pseudocode, so today is pure reading practice — the notation, not new ideas — including the Robot questions that appear every year.

2

The Point of Today

You can write it. Can you read it cold? On the exam, code is handed to you in AP Pseudocode, and you must say what it does — fast, on paper, under time pressure. That’s a different muscle from writing, and it’s trainable.

The method never changes: trace. Keep a little table of every variable, take the code one line at a time, and write down what changes. Never hold it in your head — the questions are designed to punish exactly that.

3

New Notation — the Robot

AP Pseudocode has a little robot on a grid. It faces one direction and obeys four commands:

CommandWhat it does
MOVE_FORWARD()move one square in the direction it faces
ROTATE_LEFT()turn 90° left (counter-clockwise), staying put
ROTATE_RIGHT()turn 90° right (clockwise), staying put
CAN_MOVE(dir)true if the robot could move that way (no wall/edge)
Rotating changes only the facing, not the position. The trap is forgetting which way it’s pointing after a turn. Trace a robot by tracking two things every step: its square and its direction. A move only makes sense once you know the facing.
Robots are just loops and selection in disguise. A robot program is REPEAT/IF CAN_MOVE(...) over the same iteration and selection you already know — only the “actions” are moves and turns instead of math. If you can trace a loop, you can trace a robot. Full treatment is Unit 4; today is a first taste.
4

Try It — Step the Robot

The robot starts bottom-left, facing right. Step through the commands and track both its square and its facing. Predict each step before you take it.

program: MOVE, MOVE, ROTATE_LEFT, MOVE
square: (col 1, row 1)   facing: right
next: MOVE_FORWARD()
Press Step. Watch the facing after the rotate — that is the trap.
5

Vocabulary

MOVE_FORWARD / ROTATE Programs
Robot commands: move one square in the current facing, or turn 90° without moving.
CAN_MOVE(direction) Programs
A Boolean the robot uses to check for a wall or edge before moving — selection, for robots.
6

The Gym

Eight reps in AP Pseudocode, combining everything from Units 2–3. Trace each on paper, then pick an answer.

0 of 8 answered
7

Impact Check

Reading code you didn’t write is the real job

Professional programmers spend far more time reading code — a teammate’s, an old version of their own, a library’s — than writing new code from scratch. The ability to pick up an unfamiliar program and correctly say what it does is the daily work, and it’s exactly what the exam’s pseudocode questions measure.

The trace-table habit you’re drilling isn’t a test trick; it’s how careful engineers verify that code does what they think before shipping it. Slowing down to trace is what separates “looks right” from “is right.”

8

Connections

Pulls together Units 2–3 — procedures, lists, loops, selection, and random, all in exam notation.
Next in 3.20 — the Unit 3 test, which is mostly pseudocode just like this.
Opens Unit 4 — the Robot gets its full treatment there, with longer grid programs.
Returns on the exam — Robot questions and mixed pseudocode traces are guaranteed. Track every variable; for robots, track square and facing.
← 3.18 Lab: Random Day