Range of values in switch statement

Posted on 2006-04-11
Last Modified: 2008-03-10

Hi Experts,
I am not sure if I can do this in C++.  But, can I have a range in the switch statement.
Like the following.....

switch(val) {
 case 1 to 20:
     // do something
case 21 to 100:
    // do something
  // etc
Question by:thanesh
    LVL 86

    Accepted Solution

    >>can I have a range in the switch statement.

    That's not possible unfortunately, you'll have to resort to 'if' constructions or similar here.
    LVL 1

    Author Comment

    Thanks.  That is what I thought!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now