Bug in SWITCH - ELSE: statement? [message #56318] |
Thu, 11 October 2007 02:44 |
Spon
Messages: 178 Registered: September 2007
|
Senior Member |
|
|
Hi everyone,
can someone explain this to me please?
> From the IDL helpfile for SWITCH: (I'm using V6.4)
The ELSE clause of the SWITCH statement is optional. If included, it
matches any selector expression, causing its code to be executed. For
this reason, it is usually written as the last clause in the switch
statement. **The ELSE statement is executed only if none of the
preceding statement expressions match.** If an ELSE clause is not
included and none of the values match the selector, program execution
continues immediately below the SWITCH without executing any of the
SWITCH statements.
But, for example:
PRO SWITCHTEST
N = FIX (6 * RANDOMU (S, 1) ) + 1
SWITCH N OF
1: PRINT, 'One'
2: PRINT, 'Two or less'
3: PRINT, 'Three or less'
4: PRINT, 'Four or less'
5: PRINT, 'Five or less'
6: PRINT, 'Six or less'
ELSE: PRINT, 'Are you using loaded dice?'
ENDSWITCH
PRINT, N
END
Will give me the ELSE statement every time, though N clearly will
match at least one of the preceding statements every time. Is this
just a bug or am I missing something?
Thanks
Chris
PS No, I'm not using IDL to generate die rolls really, I was using
SWITCH to fill in missing input parameters (using 'SWITCH N_PARAMS()
OF' ), but I'm drifting towards keywords instead now. :-)
|
|
|