If...Then...Else

Programming a Computer to Make Decisions - 2

In the last example the sprite only had two options, to say 'you can drive' or do nothing. If we want the sprite to choose between doing TWO things, we can use an IF... Else... statement.

In this example, if the mouse is pressed down, the sprite will say "Hello". If the mouse is not pressed down, it will say "Goodbye".

. If we want the sprite to choose between more than two options, we would use an IF...Else... statement.

Here, the sprite is choosing between three options. Hopefully by now you can see how we can keep IF...Then...Esle statements going all day and make the sprite choose between many options.

|| Else the sprite should 'B is for Beta' if the 'b' key is pressed and so on. ||
 * ~ Task
 * Your challenge here is, using the code above, get the sprite to say 'A is for Alpha' but only if the 'a' key is pressed.

A game that demonstrates a more complex use of If,,,Then...Else statements is the 'Helicopter Game'.:

The code for the helicopter sprite and the background is: Try playing this game, you may want to redesign the background to make is a bit easier!