Prev | Current Page 170 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

It does not change the if statement rules, so
true must still be returned from the expression for the proceeding code to be executed. If, however, you
require code to be executed following a false conditional expression, you can use the else keyword,
which provides an alternative route of execution in your logic. The else keyword must immediately
follow the code or block executed by an if statement:
if ( 3 == 3 )
// if true, execute this line
else
// otherwise, execute this line
It is possible to nest if statements so that multiple conditions can be met before executing certain lines
of code:
if ( thatVar == thatValue )
{
if ( thisVar == thisValue )
{
// do code
}
}
Nesting if statements mean that the nested statement will only evaluate if the outer statement is true.
You can combine the expressions in the if statements to form a single expression using the conditional
operators. Therefore, you could rewrite the example as:
if ( thatVar == thatValue & & thisVar == thisValue )
{
// do code
}
76
Part I: The Core Language
When you combine expressions in this way, the expressions are still considered separate by the virtual
machine in terms of execution.


Pages:
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182