CS I · Mon Oct 26 · 13.1 · We Do

Before the bell

  1. The I Do form in the I Do deck. All three sections. If you are here, this should be done.
  2. The We Do: Store It: What = Means to a Computer. Read each page with the class. Work every Try It in your notebook, then check it. Nothing to turn in.
  3. Bench Basics: Store It. About 30 minutes. It opens later in class on the Bench Basics slide. Write your credit code in your notebook.
  4. The exit ticket. The last 10 minutes of class, a locked form on a school Chromebook. It asks the same kinds of questions as the Try Its and the bench.

Store It: What = Means to a Computer

This section shows the three kinds of jobs on today's bench: storing a value in a box, tracing a box that changes, and finding the wrong row in a trace table.

Storing a Value

In mathematics class, the equation x = x + 1 can never be true, because no number is equal to one more than itself. In a computer program, the same symbol is an instruction to store a value. The computer first calculates the right side, and then it places the result in the box named on the left, replacing the previous value. A box can hold only one value at a time.

Before Java, this course writes a store step with an arrow, as in x ← 4, because the arrow points from the value toward the box that receives it. Java writes the same step with =, and Oracle's Java tutorial explains that = places the value from its right side into the variable on its left.

1int x = 4;
2x = x + 1;
3System.out.println(x);
5

How to work a store step:

  1. Work out the right side, using the values the boxes hold right now.
  2. Put the result in the box on the left.
  3. Cross out that box's old value. It is gone.

Example 1. Trace a ← 5, then b ← 2, then a ← a + b.

1a ← 5
2b ← 2
3a ← a + b
line   a   b
1      5   -
2      5   2
3      7   2

Line 3 works out a + b, which is 5 + 2, and stores 7 in a. The 5 is gone, and b still holds 2.

Example 2. Work n ← n + 1 when n holds 4.

1n ← 4
2n ← n + 1

The right side is 4 + 1, which is 5, so n now holds 5. The step is not a claim that n equals n + 1. It is an instruction to calculate and store.

Try It on your own

Work each one in your notebook first, then check it.

Try It 1. After line 3, what do a and b hold?

1a ← 4
2b ← 9
3a ← a + b

Try It 2. A step says k ← k * 2, and k holds 6. What does the step do?

A Box That Changes

One box can change many times. Each line reads the value the box holds at that moment, not the value it started with.

Example 3. Trace one box through four steps.

1n ← 10
2n ← n - 3
3n ← n * 2
4n ← n + 1
line   n
1      10
2      7
3      14
4      15

Example 4. A copy, not a link. Line 2 copies the value of x into y. Then x changes.

1x ← 3
2y ← x
3x ← 8
4show y
line   x   y   shown
1      3   -
2      3   3
3      8   3
4      8   3   3

Line 2 copies 3 into y. Line 3 changes x to 8, but y keeps the 3 it was given, so line 4 shows 3.

Try It on your own

Work each one in your notebook first, then check it.

Try It 3. What does n hold after line 4?

1n ← 20
2n ← n - 5
3n ← n * 3
4n ← n + 2

Try It 4. What does line 4 show?

1m ← 7
2k ← m
3m ← 1
4show k

Try It 5. Make a trace table for these lines. Write what x and y hold after each line.

1x ← 2
2y ← x + 3
3x ← y * 2
Check your answer

Line 1: x is 2, y is empty. Line 2: x is 2, y is 5. Line 3: x is 10, y is 5.

Find the Wrong Row

Bench Basics sometimes shows a trace table that a student filled in and asks which row is wrong. Check each row in order, using the values from the row above it. The first row that does not match is the wrong one, and every row after it may be wrong too.

Example 5. A student traced these lines. Find the wrong row.

1p ← 6
2q ← p + p
3p ← q - 1
line   p    q        the student wrote
1      6    -        p is 6
2      6    66       q is 66
3      65   66       p is 65

Row 2 is wrong. The step p + p adds two 6s, which is 12, not 66. The student wrote the digits side by side instead of adding. Row 3 is wrong only because it used the wrong q. With q holding 12, line 3 stores 11 in p.

The bench catches two common mistakes. The first is using an old value after it was replaced, such as still using 4 for x after it changed. The second is reading = or the arrow as "is equal to" instead of "store."

Sources: College Board, AP Computer Science Principles Exam Reference Information (2025); Oracle, Assignment, Arithmetic, and Unary Operators (n.d.); Code.org, CS Principles 2020–2021 Unit 4 Standards (n.d.).

Try It on your own

Work each one in your notebook first, then check it.

Try It 6. A student traced these lines and wrote: line 1, c is 3. Line 2, d is 9. Line 3, c is 9. Which row is wrong?

1c ← 3
2d ← c + c
3c ← d + 1

Bench Basics

Store It

Open the bench and work the jobs in order. They get harder as you go. Write your credit code in your notebook, then paste it into the credit-code form.

Bench Basics opens during your class period.

Exit Ticket

Open it on a school Chromebook. Locked mode does not work on a lab computer.

The exit ticket opens 10 minutes before the bell.