[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


Ranges in case statements

When ANSI strictness is off, CodeWarrior C allows ranges of values in a switch statement by using a special form of case statement. A case statement that uses a range is a shorter way of specifying consecutive case statements that span a range of values. Listing 3.8 shows an example.

The range form of a case statement is


  case low ... high :

where low is a valid case expression that is less than high, which is also a valid case expression. A case statement that uses a range is applied when the switch statement's expression is equal to or greater than the low expression while being equal to or less than the high expression.


NOTE

Make sure to separate the ellipsis (...) from the low and high expressions with spaces.
Ranges in case statements:
switch (i)
{
  case 0  ...  2: /* Equivalent to case 0: case 1: case 2: */
    j = i * 2;
    break;
  case 3:
    j = i;
    break;
  default:
    j = 0;
    break;
}


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 17, 2000