Internal workings of Case

BlitzMax Forums/BlitzMax Programming/Internal workings of Case

Steve Elliott(Posted 2005) [#1]
Could Mark/BR confirm if each Case statement once matched now exits the Select/End Select structure?

In previous versions this wasn't the case (excuse the pun) and each option was replaced with an If - which is slower because each If/Case has to be looked at before reaching End Select.

C++ uses the break command for this - but the nearest command in Blitz is Exit - which exits the whole loop. If it does read all case statements could this optimization be introduced?


Yan(Posted 2005) [#2]
In previous versions this wasn't the case
Yes it was!..And is...

Try this (in classic blitz and bmax)...
a = 10

Select True
	Case a > 1
		Print "bigger than 1"
	
	Case a > 2
		Print "bigger than 2"
	
	Case a > 3
		Print "bigger than 3"
End Select

Input

End
AFAIR 'Select...Case' is treated as an 'If...ElseIf' block.


Steve Elliott(Posted 2005) [#3]
Interesting.


BlitzSupport(Posted 2005) [#4]
Yeah, Blitz has always exited on a match...


skn3(Posted 2005) [#5]
Is there a command to stop it from exiting?

*edit* Obviously if it is if based then no, but that sucks :P Proper select/case is much better.

const someconst1 = 123
const someconst2 = 56

local condition = 56
select condition
	case 56,57,58,59
		print "match range"
		continue
	case 56
		print "match exact"
		continue
		
	case someconst2
		print "match constant 1"
		continue
		
	case someconst1
		print "match constant 2"
		continue
		
	default
		print "default match"
end select
rem
	would output
	
	match range
	match exact
	match constant 2
	default match
endrem



FlameDuck(Posted 2005) [#6]
LOL!


BlitzSupport(Posted 2005) [#7]
Doesn't seem to have been missed much over the last 5 years (or 10-15 if you include Amiga Blitz)...


skn3(Posted 2005) [#8]
Yeah its not the end of the world, its just annoying knowing that it is done in other languages.