What they are
Conditionals are a set of statements that are executed ONLY if some conditions are met.
The two main types are the IF statements and the SWITCH statements.
Link to Adobe Help HERE
Conditionals are a set of statements that are executed ONLY if some conditions are met.
The two main types are the IF statements and the SWITCH statements.
Link to Adobe Help HERE
The If statement has 2 parts: the first logical structure placed in the condition, and the second statements, that will only be run when the first condition returns a value of "true". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Multiple conditions (&&) (||)
|
The If statements checks if whether the value of the variable score is greater than 65. If the condition is satisfied, the secons statement is run, changing the value of the second variable. The word "if" is followed by a set of parenthesis which contain the condition. If the condition is true, then Flash will execute the code in the curly brackets, otherwise it will ignore the statement altogether. It could also be written in this compressed format: |
With the If...else stucture you can add an alternative depending on the return value of the first logical structure (true or false). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Let's say the condition from any one of the examples above is not met. Flash will ignore the block code in the curly brackets and continue executing the program normally. In many cases you may want to execute a different set of code, but only if the condition is not met. This is where the else keyword comes into play. The else allows you to post a different block of code that will execute should the condition not be met. |
In the If...else if stucture the conditions are checked one at a time, sequentially. Once a condition is found to be true, the statement/s for that condition will be run and the rest of the conditions and statements will not be checked. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Since the conditions are going to be run sequentially the order of the statements matter. If the first condition had be if (score>65) grade = 65 Every student with more than 65 points would have got a D! |
In the switch stucture can be used as an alternative for If...else if...else if in cases where a single expression or variable is compared against several vlaues. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The single variable score is compared against 100, 200 and 300.
|