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

Survivors

Artist: Jeff Kulak

Jeff is a senior graphic designer at Science World. His illustration work has been published in the Walrus, The National Post, Reader’s Digest and Chickadee Magazine. He loves to make music, ride bikes, and spend time in the forest.

Egg BB

Artist: Jeff Kulak

Jeff is a senior graphic designer at Science World. His illustration work has been published in the Walrus, The National Post, Reader’s Digest and Chickadee Magazine. He loves to make music, ride bikes, and spend time in the forest.

Comet Crisp

Artist: Jeff Kulak

Jeff is a senior graphic designer at Science World. His illustration work has been published in the Walrus, The National Post, Reader’s Digest and Chickadee Magazine. He loves to make music, ride bikes, and spend time in the forest.

T-Rex and Baby

Artist: Michelle Yong

Michelle is a designer with a focus on creating joyful digital experiences! She enjoys exploring the potential forms that an idea can express itself in and helping then take shape.

Buddy the T-Rex

Artist: Michelle Yong

Michelle is a designer with a focus on creating joyful digital experiences! She enjoys exploring the potential forms that an idea can express itself in and helping then take shape.

Geodessy

Artist: Michelle Yong

Michelle is a designer with a focus on creating joyful digital experiences! She enjoys exploring the potential forms that an idea can express itself in and helping then take shape.

Science Buddies

Artist: Ty Dale

From Canada, Ty was born in Vancouver, British Columbia in 1993. From his chaotic workspace he draws in several different illustrative styles with thick outlines, bold colours and quirky-child like drawings. Ty distils the world around him into its basic geometry, prompting us to look at the mundane in a different way.

Western Dinosaur

Artist: Ty Dale

From Canada, Ty was born in Vancouver, British Columbia in 1993. From his chaotic workspace he draws in several different illustrative styles with thick outlines, bold colours and quirky-child like drawings. Ty distils the world around him into its basic geometry, prompting us to look at the mundane in a different way.