Skip to content

3. Conditions

The if and if / else blocks are the decision diamond from Unit 1, now with a hexagonal slot for the yes/no question.

if <touching [edge]?> then
    turn (180) degrees

if <key [space] pressed?> then
    change y by (10)
else
    change y by (-10)

Anything that fits in a hexagon — touching, key pressed, > / < / = comparisons — can go in the condition slot, and you can combine them with and, or, not.

Try it

Make your sprite bounce: if it's touching the edge, turn around; otherwise, keep moving forward.

Tip

if / else always runs exactly one of its two branches — just like the two arrows out of a decision diamond.

Next: Loops →