Page 1 of 1
					
				[Implemented] Commas in 'select' statement?
				Posted: Mon Apr 19, 2004 4:24 pm
				by Kris_a
				I had a quick search for something similar to this and found nothing, which was really suprising.
Code: Select all
Select Somevar
  case 1,2,3,4
    ; Do something
  case 5,6,7,8
    ; Do something else
endselect
This would be incredibly handy, at the moment I'm forced to use functions to execute the same code in two different 'select' situations.
Thanks 
-Kris
 
			 
			
					
				
				Posted: Mon Apr 19, 2004 9:46 pm
				by blueznl
				you're not the first one who wishes this...
			 
			
					
				Alternative syntax
				Posted: Tue Apr 20, 2004 12:27 am
				by USCode
				I've seen some languages implement it this way:
Code: Select all
Select Somevar 
  case 1
  case 2
  case 3
  case 4
    ; Do something 
  case 5
  case 6
  case 7
  case 8 
    ; Do something else 
endselect 
Unfortunately, that doesn't work as desired in PB.  BUT that kind of syntax might be easier for Fred to implement.
 
			 
			
					
				Re: Alternative syntax
				Posted: Tue Apr 20, 2004 5:15 pm
				by GPI
				USCode wrote:I've seen some languages implement it this way:
Code: Select all
Select Somevar 
  case 1
  case 2
  case 3
  case 4
    ; Do something 
  case 5
  case 6
  case 7
  case 8 
    ; Do something else 
endselect 
 
Of all possibiltys the worst methode (and take much more writing-time).
When i remember right, C use something like this, but there you must exit a case with a "break" or it will run in the other case-statement...
 
			 
			
					
				
				Posted: Tue Apr 20, 2004 9:01 pm
				by blueznl
				i'd settle for the more or less common basic syntax:
case 1,2,3
case 3
default
etc.
			 
			
					
				Re: Commas in 'select' statement?
				Posted: Wed Apr 21, 2004 12:26 am
				by PB
				> at the moment I'm forced to use functions
You could also just use 
If...ElseIf...EndIf like so:
Code: Select all
If Somevar>0 and Somevar<5 ; case 1,2,3,4
  ; Do something
ElseIf Somevar>4 and Somevar<9 ; case 5,6,7,8
  ; Do something else
EndIf
 
			 
			
					
				Me too...
				Posted: Wed Apr 21, 2004 7:35 am
				by Alberto
				I need lthis feature.
It's not indispensable but it's frustrating to fill the code with 
if...
if...
if...
if... 
 
A solution maybe the use of commas (is the best solution) or the use of a 'break' instruction like in the C language.
Ciao
Alberto
 
			 
			
					
				Re: Me too...
				Posted: Wed Apr 21, 2004 8:56 am
				by PB
				> it's frustrating to fill the code with If, If, If, ...
It's no more frustrating than using multiple Case statements.
> or the use of a 'break' instruction like in the C language
PureBasic does have a Break command (see the docs).
			 
			
					
				
				Posted: Wed Apr 21, 2004 9:12 am
				by Dare2
				But does not need breaks in Select/Case, and hopefully it stays like that.
However, 
case 1,2,5,9 TO 15,etc would be nice.
But first: Floats, fixed strings, thread safety, etc!  
