[Implemented] case select with multiple options

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

[Implemented] case select with multiple options

Post by blueznl »

(from the beginners forum)

currently, every case can only have 1 expression

select a
case 1
case 2
case 3
endselect

is it possible to get more expressions per case?

select a
case 1 , 2
case 3
endselect

it beats a long list of if / elseif / elseif / endif...
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Yeeeeah!, that is a good request, because sometimes is very needed.

And not just only things like "Case 3,4,5,6" but also like "Case 2 To 29" would be fine, fine, fine. :idea:


AL
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

you mean fine to fine? :wink:
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Yeah! :wink:
and nice to nice :wink:

But Fred is surely thinking in other matters. :cry:
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: case select with multiple options

Post by PB »

> is it possible to get more expressions per case?
> it beats a long list of if / elseif / elseif / endif...

Actually, If/ElseIf uses less code than Case:

Code: Select all

Select a
  Case 1,2                 If a=1 Or a=2
    Debug "1 or 2"           Debug "1 or 2"
  Case 3                   ElseIf a=3
    Debug "3"                Debug "3"
  Case 4 To 10             ElseIf a>3 And a<11
    Debug "4 to 10"          Debug "4 to 10"
EndSelect                  EndIf

Case = 113 bytes.          If/EndIf = 103 bytes.
:wink:
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

readability, you... you... you... goto lover!

:-)
Fred
Administrator
Administrator
Posts: 18441
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

The fact is than: Case 1,2 or Case 1 to 10 doens't work actually ! A check has been added for the new version (that's why it's shorter here too)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> readability, you... you... you... goto lover!

LOL! :lol:
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

it was the best insult i could come up with :)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply