if/else  Loop statements

Chapter 1: Overview

switch

The switch statement performs the same kind of comparison as the third format of the if/else statement; it executes a specific statement or set of statements based upon the comparison of different simple type constants to a simple type variable.

Table 1-9: Switch statement

Format

Meaning

switch (fixed-length type variable) {

case constant1: statement1; statement2; break; case constant2: statement3; break; default: statement4; statement5; }

If the variable equals constant1, then all statements from here... to this break are executed.

If the value of the variable equals constant2, then all statements from here... to this break are executed.

If the value of the variable does not equal any of the constants, then all statements from here... to the end of the switch statement are executed.

NoteA fixed-length variable is one of the following types: int, short, long, char, and the unsigned variants of those, namely, unsigned int, unsigned short, unsigned long, and unsigned char. All other types, including string and float, are considered complex datatypes in ODL, and do not work correctly as variables in the switch statement.





Copyright © 2005. Sybase Inc. All rights reserved. Loop statements

View this book as PDF