And in fact, the closest approximation of switch/case, currently, would use exactly that: GOTO %switchlabel
; switch(condition) {
; case 1,2:
; code here
; break;
; case 3:
; code here
; break;
; case N:
; code here
; break;
; else
; code here
; } // End of switch(condition)
if (condition) {
goto $ifmatch
:1
:2
; command(s)
goto EndOf.Switch | ; break
:3
; command(s)
goto EndOf.Switch | ; break
:N
; command(s)
; Since this is the last section, goto EndOf.Switch is redundant
:EndOf.Switch
}
else {
; command(s)
}
One pass through evaluating the condition and then go directly to the appropriate section of code (which is the benefit of using switch). Switch is a special case of IF-ELSEIF-ELSE where the exact same condition applies to each case, varying only in the value. This is, in fact, a good example of when you probably SHOULD use GOTO over IF-ELSEIF-ELSE, if speed is an issue.