All Resources

Control : If-then and Repeat-until

If-then logic and loops using "repeat-until" are key parts of any computer language. In particular, these allow the construction of games with goals and scoring.

Objectives

  • Introduce If-then logic and loops.

Materials

  • Per Student Pair:
    1 computer per two students (one computer per student is better)

  • Per Class:
    computer with projector or SMART board.

Key Questions

  • What happens when you run the logic in step 6? (Nothing, because the computer only checks for the condition once, and then moves on.)
  • What happens when you run the logic in step 7? (When you press the space key, the sprite moves up and to the right.)

What To Do

Preparation:

Ensure that all the computers work, and are connected to the internet.
Set up the instructor computer and projector or SMART board.  Log in to the Scratch website.

Acitvity:

Instructor

  1. Explain that the next goal will be to control a sprite using the arrow keys.
  2. On the screen or SMART Board, open a new scratch project and select the Control tab.
  3. Explain that an “if-then” block will do what is inside it, as long as the condition in the block is true.
  4. Select the sensing tab, and show students where to find the “key pressed” block.
  5. Have students follow along on their own computers as you assemble this logic:

  1. Have students run the program.  What happens?
  2. Have students follow along on their own computers and add in a “forever” block like this:

  1. Have students run the program.  What happens?
  2. (optional) Create this logic; it has the same result as the logic in step 7.

Students:

  1. Create a program where a sprite is controlled by the four arrow keys on the keyboard.  Pressing the arrow should move the sprite in the corresponding direction.

Modification: Use the “repeat-until” block and the “touching_?” block to change your program so that the sprite changes when it bumps into another sprite

Extensions