Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / question about CASE statement

Author
Message
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 28th Jul 2010 06:21
Is there a syntax for using a range of values in a CASE block?

We can use

CASE 1,2,3,4,5

but I seem to recall some BASICs being able to use

CASE 1 TO 5

Does DBPro have anything like this?

HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 28th Jul 2010 13:37
No, DBPro does not let you do that, you have to put every value you need in the range in.

Another one for the wish list.

Dark Physics makes any hot drink go cold.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Jul 2010 23:19
Why not just use "IF" in that 'case'?



It's actually less code in most cases...

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 29th Jul 2010 00:36
Yah, I do that if it's simpler.

Or sometimes I use the default case block to hold a range, like this...



I was just curious if TGC had included the range part of CASE.

Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 30th Jul 2010 22:17
Can you not do...

Select var
for i= 1 to 5
case i

do stuff

endcase
next i

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Jul 2010 22:31
No.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 31st Jul 2010 01:07
ummm... why? :-p

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Jul 2010 01:14
It doesn't compile.

The argument of a case statement must be a literal such as 0, 1, "help", "read", 1.1, etc. In other words not a variable.

Login to post a reply

Server time is: 2026-07-25 08:28:25
Your offset time is: 2026-07-25 08:28:25