Prev | Current Page 174 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

..
}
You can provide as many case statements as is needed for each else if statement that would otherwise
facilitate the comparison. Each case keyword is supplied the value for the comparison and the line is
ended with a colon (:), which indicates the end of the case and the start of the code block to execute
78
Part I: The Core Language
following a match. If you then require a final else statement to provide the catchall clause, you use the
default keyword:
switch ( myValue )
{
case val1:
// do code
case val2:
// do code
...
default:
// if all else fails, do this
}
When a switch statement is executed, the virtual machine executing the code will compare the given
value with each case until a match is made or the end of the switch statement has been found. In many
languages, once a match is made and the relevant code for that case is executed, the next case ??™ s code
segment is executed even if the case ??™ s comparison value is not a match, and then the next, and so on
until the end of the switch block has been reached or a break keyword is found.


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