# Lesson 3.1

## Example 3.1.1: (of an if statement) ## The condition is a Boolean statement – something which evaluates to true or false. For if statements the block of code may or may not get run. If the Boolean expression is true it is run, otherwise nothing happens – the next line of code is run as if the if statement were not there. Consider the diagram below. ## Example 3.1.2: (of an (if) else statement) ## For if else statements one of the two blocks of code will run. If the Boolean expression is true the 1st is run, otherwise the 2nd is run. Consider the diagram below. ## Example 3.1.3: (of an (if) else if statement) ## For (if) else if statements one of the two blocks of code may or may not get run. If the 1st Boolean expression is true the 1st is run, if the 2nd Boolean expression is true the 2nd is run, otherwise nothing happens – the next line of code is run as if the (if else if) statements were not there. ## Boolean expression use Comparison Operators

Given that x = 5 consider the following evaluations.

Example Operator Description Result
(x == 20) == equal to false
(x != 20) != not equal to true
(x > 20) > greater than false
(x >= 20) >= greater than or equal to false
(x < 20) < less than true
(x <= 20) <= less than or equal to true

## Have the first at (100,200) turn and stay red if the mouse position is greater than 100 but return to white if less than 100. Have the second at (200,200) turn and stay green if the mouse position is greater than 200 but return to white if less than 200. Have the third at (300,200) turn and stay blue if the mouse position is greater than 300 but return to white if less than 300    