Goal: Display "Hello World" if the value of a variable named "option" is 1 else display "Welcome".
If statement allow the flow of the program to be changed, which leads to more interesting code.
Syntax:
IF (boolean condition) THEN
(consequent) ELSE (alternative) END IF
On the second row of the actions box, there is a "?" block. Click on that to implement an if statement.
Three blocks should appear on your screen. The top indicates the start of the if. The second is the else. The bottom indicates the end of the if statement.
Clicking on the red arrow on the right side of the top block will open up a boolean menu. If the expression evaluates to true, any blocks between it and the middle "if" block will execute. Otherwise any blocks between the middle and the bottom will execute.
Click the equal to sign. This block can accept two values. Select the variable as one value and 1 in the other value as shown below.
Complete program is shown below.
Run the program first with option value 1 and then with option value 2. First "Hello World" and then "Welcome" should be displayed respectively.
Activity: Display "Hello World" if the value of "option" is 1. Display "Welcome" if the value of the option is 2. Else display "Ready"