comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Bug in SWITCH - ELSE: statement?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Bug in SWITCH - ELSE: statement? [message #56318] Thu, 11 October 2007 02:44
Spon is currently offline  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. :-)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: boost::multi_array
Next Topic: Problem while deleting shape file

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 02:58:36 PDT 2025

Total time taken to generate the page: 1.65173 seconds