Download presentation
Presentation is loading. Please wait.
Published byGary Alvin Anthony Modified over 9 years ago
1
1
2
We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is called the flow of control Today we will learn how to change this so our programs can branch in different directions 2
3
A conditional statement lets us choose which statement will be executed next (branching) Conditional statements give us the power to make basic decisions We will use ActionScript’s conditional statements if, if else, else 3
4
The if statement has the following syntax: 4 if ( condition ) { statement; } if is an ActionScript reserved word The condition must be a Boolean expression. It must evaluate to either true or false. If the condition is true, the statement is executed. If it is false, the statement is skipped.
5
5 score > 10 trace(“winner”) true false if (score > 10) { trace(“winner"); }
6
Our conditions will be written using Boolean expressions such as (score > 10) Do you know your relational and logical operators? What do these mean? 6 Less than < Greater than > Less than or equal to <= Greater than or equal to >= Equal to == Not equal to !=
7
7 age >=18 trace(“adult”) true false trace(“kid”) if (age >= 18) { trace(“adult"); } else { trace(“kid"); } Note: One or the other will be executed, but not both.
8
You can test more than one condition at a time by using an if and then else if 8 if (x > 20) { trace("x is > 20"); } else if (x < 0) { trace("x is negative"); } else { trace(“x =0”); } This condition is only tested if x>20 is false This only runs if the earlier tests both were false
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.