SWITCH( ) Statement |
|
Allows easy testing of
multiple values. 1. The constant 'test', having been assigned the value of 3, would work as shown. 2. 5 and 1 would execute the same code. 3. Always use the 'DEFAULT' case, some compilers will behave oddly and possibly generate a lot of extra code if it is not included. 4. An omitted [BREAK;] at the end a block will have the effect of running extra code. ie, omitting the [BREAK;] in the [CASE 0:] block will allow a value of 0 to run "code 0" and "code 5/1" |
CHAR temp; CHAR CONST test = 3; SWITCH (temp){ CASE 0: { //code 0 BREAK; } CASE 5: CASE 1: { //code 5/1 BREAK; } CASE test: CASE 3: { //code test/3 BREAK; } DEFAULT: BREAK; } |
Any questions or comments?
This page last updated on
August 28, 2011