Loading...

if else - part 1

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?

1 == 3

Compile the program and test it on your BOB3.

What happens now?

8 == 8

What do you expect will happen?

Compile the program and see if you’re idea was right!
1: True or false: 9 == 6
2: True or false: 155 == 155
3: True or false: 8 == 5+3
4: True or false: 14 == 20-5
 You haven’t completed anything yet!
 Super, so far so good…
 Super, you got it all right!
 Sadly not correct…
 One answer is correct
 A couple are correct…