Go to the previous, next section.

Case Ranges

You can specify a range of consecutive values in a single case label, like this:

case low ... high:

This has the same effect as the proper number of individual case labels, one for each integer value from low to high, inclusive.

This feature is especially useful for ranges of ASCII character codes:

case 'A' ... 'Z':

Be careful: Write spaces around the ..., for otherwise it may be parsed wrong when you use it with integer values. For example, write this:

case 1 ... 5:

rather than this:

case 1...5:

Warning to C++ users: When compiling C++, you must write two dots `..' rather than three to specify a range in case statements, thus:

case 'A' .. 'Z':

This is an anachronism in the GNU C++ front end, and will be rectified in a future release.

Go to the previous, next section.