We help IT Professionals succeed at work.

Can case within switch statement specify range of values ?

naseeam
naseeam asked
on
208 Views
Last Modified: 2016-08-11
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 ?
Comment
Watch Question

Kent OlsenData Warehouse / Database Architect
CERTIFIED EXPERT

Commented:
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

Author

Commented:
could you provide example of placing multiple values in same block?
Data Warehouse / Database Architect
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.