BOB3 is going to reveal the truth!
We’re going to programme BOB3 to recognise true and false by giving a him a question:
If it’s true, the lights should light green, otherwise they should be red.
To programme this, we use:
if - else
The compiler executes
- either all the commands in the
if
block - or all the commands in the
else
block.
A block is all the commands in curly brackets/braces { }
.
BOB decides which block to run by checking to see if the condition in line 12 is true or false:
if (1 == 1)
==
mens "exact equal"
1 == 1
is true
1 == 3
is false, because a one is not a three!
Compile the program and test it on your BOB3.
What happens?
Change the condition to:
1 == 3
Compile the program and test it on your BOB3.
What happens now?
Change the condition again:
8 == 8
What do you expect will happen?
Compile the program and see if you’re idea was right!