Skip to content
Exit presentation

Programming with Blocks II

Changing what is in the box

A box holds 0. Each tap must make it bigger by one.

score holds 4.
Step 1 of 3
  1. score holds 4.
  2. Read 4. Work out 5.
  3. Write 5 back. The 4 is gone.

The block says add 1 to score.

The first run changed the box from 4 to 5. Start the block again and the box holds 6, not 5. The second run starts from 5, so 5 + 1 = 6.

Rule: An add block reads the number in the box. It works out the new number. It writes that back.

A repeat block runs its inside blocks a set number of times. Put an add block inside it. The box starts at 0. Repeat 4 times, add 3: the box holds 3, 6, 9, 12.

Watch out!

score = score + 1 is not a Maths equation. It is an order: read the box, then write the new number.

Slide the two numbers. Make score end at 12.

Loading lab…

Jump to lesson

This track

  1. 0 Start here
  2. 1 A box with a name on it
  3. 2 Changing what is in the box
  4. 3 Waiting for something to happen
  5. 4 One block inside another
  6. 5 Plan it before you build it
  7. 6 The big picture
  8. 7 Track quiz

Other tracks