FIRST STEPS: DECISIONS

FIRST STEPS: DECISIONS

If..., then it happens... or it happens...

Easy

15 mins

from 8 years on

In this lesson we’ll be using the editor from Open Roberta. Be careful to ensure that the following image is visible at the top right of your programming environment. You can find the editor on our website. Just click on ‘Let’s Start’ and then ‘Editor’.

FIRST STEPS: DECISIONS

Options within a program can be made dependent not only on inputs, but also on other conditions. For example, you can create an oracle that randomly shows a sad or a happy smiley:

1IF – THEN DO RELATIONSHIP

The actions to the right of do are only executed if the condition to the right of if is fulfilled.

In this case, the heart will not be visible on the LED grid, as the decision variable is not equal to 1. You can find the if...do block in the Control menu.

2And on we go

After the if...do block the program continues in any case, no matter whether the condition was fulfilled before or not.

Since the condition in the wait...until block is not fulfilled, only the note is displayed on the LED grid at program start.

3If – then – else

If you expand the if...do block, the first if condition is checked first, if it is not fulfilled the second if condition is checked. Only those actions are triggered for which the associated condition is fulfilled.

Click on the + to the left of if to unfold the if...do block. The probability to display either a happy or a sad smiley on the LED grid is 50/50.