Sambar Server Documentation

CScript Switch Statement


The switch statement provides a mechism for executing multi-way decisions. It is used when only one variable is being tested and all branches must depend on the value of that variable. Each possible value of the switch statement variable can control a single branch. A final, catch all, default branch may optionally be used to trap all unspecified cases.
printvar(n) { /* Print the value associated with n */ switch(n) { case 0 : printf("None\n"); break; case 1 : printf("One\n"); break; case 2 : case 3 : case 4 : printf("Many\n"); break; default : printf("Lots\n"); break; } }

The break statement prevents any further statements from being executed by leaving the switch. Since case 2 and case 3 have no following break, they continue on allowing the same action for several values of n.

© 2001 Sambar Technologies. All rights reserved. Terms of Use.