Raised This Month: $ Target: $400
 0% 

Case ranges in switch statements.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mcpan313
Senior Member
Join Date: Mar 2010
Old 02-11-2013 , 01:14   Case ranges in switch statements.
Reply With Quote #1

Does sourcepawn support this? If yes, how to use it?

Test code
__________________
sorry, for my poor english.
mcpan313 is offline
Send a message via MSN to mcpan313
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 02-11-2013 , 03:39   Re: Case ranges in switch statements.
Reply With Quote #2

I think the closest you can get is this.
PHP Code:
switch(150)
{
    case 
1,2,3,4,5,6,7,8,9,10:
    {
    }
    default:
    {
    }

I suggest you use an normal if else with ranges.

Yours sincerey
Impact
__________________
Impact123 is offline
mcpan313
Senior Member
Join Date: Mar 2010
Old 02-11-2013 , 06:16   Re: Case ranges in switch statements.
Reply With Quote #3

Quote:
Originally Posted by Impact123 View Post
I think the closest you can get is this.
PHP Code:
switch(150)
{
    case 
1,2,3,4,5,6,7,8,9,10:
    {
    }
    default:
    {
    }

Thanks, I know this, but if the ranges so large...

Quote:
Originally Posted by Impact123 View Post
I suggest you use an normal if else with ranges.
In fact I think so, too
__________________
sorry, for my poor english.
mcpan313 is offline
Send a message via MSN to mcpan313
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 02-11-2013 , 07:44   Re: Case ranges in switch statements.
Reply With Quote #4

Hmm, I wonder why did they remove that, in AMXX Pawn it was like this:
Code:
switch (num) {     case 1..20: {}     // or     case 21 .. 100: {} }
__________________
hleV is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-11-2013 , 08:11   Re: Case ranges in switch statements.
Reply With Quote #5

Quote:
Originally Posted by hleV View Post
Hmm, I wonder why did they remove that, in AMXX Pawn it was like this:
Code:
switch (num) {     case 1..20: {}     // or     case 21 .. 100: {} }
It's pointless as it'll almost always optimise out to a if..elseif..else tree, and if it wouldn't optimise to that, it would be short enough to specify all the cases.
__________________
asherkin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode