In Flash ActionScripting, three basic conditional statements a used for to control the program flow. The major conditional sta
ments that are used include:
1. If ... else
2.If .. else if
3. Switch
If.... Else Statement
This is one of the most important conditional stateme which helps the user to test a condition and. execute a block code which is dependent on the truth or falsity of the conditi This can be suitably illustrated by the following example.
if (x > 20)
{
trace ("x is > 20") ;
}
else
{
trace (" x is <= 20) ;
}
The above block of code checks the condition i.e x > 20. If true, then the statement within the curly braces is executed. If condition is false, the statement within the else part will be cuted. For executing an alternative block of code, the if state without the else part can be used.
If .....Else If statement
For testing more than one condition, the if else if statement can be used. This can be illustrated by the example given below. The code shown below not only tests whether the value ofx exceeds 20, but 'also tests whether the value ofx is negative.
if (x > 20)
{
trace ("x is > 20") ;
}
else if (x < 0)
{
trace ("x is negative");
}
Switch
Out of the three conditional statements, the switch statement is the most powerful one. This statement can be suitably used when there are several execution paths that are dependent on the same conditional expressions. The switch statement starts off with a case statement and ends with a break statement. This can be described by the following example where the statement prints the day of the week, based on the day number returned by the Date.getDay () method.
var sameDateate = new Date();
var dayNum:uint = sameDate.getDay();
switch (payNumber)
(
case 0:
trace ("Sunday") ;
break;
case 1:
trace ("Monday") ;
break;
case 2:
traCe("Tuesday");
break;
case 3:
trace("Wednesday");
break;
case 4:
trace("Thursday");
break;
case 5:
trace ("Friday") ;
break;
case 6:
trace("Saturday");
break;
default:
trace ("Out of range");
break;
}



ate = new Date();
Reply With Quote
Bookmarks