Jump to content
  • Advertisement
Sign in to follow this  
gnomer

switch range?

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

quick question. can you put a range in a switch case or do you have to resort to if statements? like: case 50-100: something; break; case 0-49: something; break; is there a way to do this?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Of course there is a way, but the if is better.


case 0:
case 1:
case 2:
case 3:
/*code that handles 0,1,2,3 */

Share this post


Link to post
Share on other sites
Kids these days... Spoiled by languages that let you do interesting things with cases. In my day we counted ourselved lucky to have have switch/case at all!

Share this post


Link to post
Share on other sites
The problem is that C/C++/Java/etc. 'switch' is a potential-optimization tool that looks like a powerful expression idiom, whereas 'switch' in "friendlier" languages is a powerful expression idiom that looks like a potential-optimization tool... I suppose both are possibly dangerous :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!