Prev | Current Page 175 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

In haXe, however, this
is not the case (excuse the pun). Only the code associated with a case that has a matching comparison
value will be executed. Once this has happened, the switch statement is automatically exited and the
rest of the application is resumed. No break keyword is required by the case to allow this, and indeed,
supplying a break in a switch statement will cause a Break in loop compiler error, as the break
keyword is not associated with the switch or case keywords. The benefit to this, however, is that the
default case does not have to exist at the end of a switch case list, but can be put anywhere in this list.
If you require blocks of code to be executed for several different case statements, it is advisable to
supply a function as the executable code so as to facilitate maintaining the logic in one place.
Returning Values from Conditional Statements
Unlike many languages, the if and switch statements in haXe can return a value. This is extremely
useful for reducing unnecessary code and increasing readability.


Pages:
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187