Prev | Current Page 168 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Conditional Statements
Depending on your perspective, conditional statements can be seen as one of the most basic forms of
data flow processes, as they perform the simple task of herding your data through your application logic
based on decisions. These decisions can be achieved using conditional expressions (expressions
evaluated through the use of conditional operators) or as the return value of a function or calculated
expression. In haXe, a condition is a Boolean value of either true or false and can be represented by no
other type. If a decision is to be made on an expression returning a type other than a Boolean, then the
Std.bool() function can be applied to cast the expression into a Boolean value. For example:
// produces a compile error
if ( 3 + 2 ) someVar = someValue;
// will compile successfully
if ( Std.bool( 3 + 2 ) ) someVar = someValue;
if Statements
The if statement is the most basic and malleable of the conditional keywords and will likely supply the
greater number of conditional statements in your applications.


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