Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

Can case within switch statement specify range of values ?

signed short  position;

switch (position)
{
   case ( 500 to 1250)
   {
         /* set some variable */
         break;
   }

   case (100 to 499)
   {
         /* set some variable */
        break;
   }

   case (-200 to 99)
   {
        /* set some variable */
       break;
   }

   default:
   {
       /* set some variable */
       break;
   }
}

Open in new window


If not, what other constructs can be used besides if - else ?
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

No.  

The C switch statement requires exact values, though you can place multiple values in the same block.

For what you're describing, the structure

  if () else if ()

is probably the best.


Kent
Avatar of naseeam

ASKER

could you provide example of placing multiple values in same block?
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial