IF demo
Mouse Buttons and if
This exercise introduces decision structures. Notice the if statement looks like a loop. If the expression inside the brackets evaluates as true then the sketch will execute the lines of code between the braces. A more complex decision structure can be made using if, else if and else.
if (expression1){
... do something1
}
else if (expression2){
... do something2
}
else if (expression3){
... do something3
}
else{
... do something4
}
In this example if expression 1 evaluates as true then the sketch will execute something1 and then continue executing the code after the else braces.
If expression1 evaluates as false and expression2 evaluates as true then the sketch will execute something2 and then continue after the last else brace.
If none of the expressions evaluate as true then the sketch will execute something4.
You can have as many lines of code as necessary between the braces in an if structure.
Finally. Notice that the expression used in the example is (mousePressed == true) and NOT (mousePressed = true). Using just one equals sign will force mousePressed to be true. Two equals signs is like saying 'the same as'.
22.1 Modify the sketch so that the entire letter H is black instead of grey.
If, else if, else demo
Try changing the value of myx.