0

If and else

  1. yes
    no

    Two choices

    If it is sunny, we play in the park. Else, we read a book inside. We always do one of them.

  2. if the way right is blocked
    move down
    else
    move right

    The else block

    The robot asks: is the way right blocked? A rock says yes. So it moves down. The else part is skipped.

  3. if the way right is blocked
    move down
    else
    move right

    When the answer is no

    Same blocks, no rock this time. The answer is no. So the robot skips the if part and does the else part.

  4. repeat 6 times
    if the way right is blocked
    move down
    else
    move right

    Ask again and again

    Put if and else inside a repeat. The robot asks at every step. It climbs down the rocks like stairs!

For parents

Goal: Your child learns that if and else pick one of two paths: the if part when the answer is yes, the else part when it is no.

  • Make up if and else rules together: if you finish your plate, you get fruit, else you try two more bites.
  • As the robot runs, ask: which part will it do this time, the if or the else?
  • Point out that the robot never does both parts in one turn.

Away from the screen: Play a hallway game. Rule: if there is a pillow in front of you, step to the side, else step forward. Put pillows on the floor and let your child follow the rule to the end.

Coding · Making Choices
Back to top