re: Bug in SWITCH - ELSE: statement? [message #56311] |
Thu, 11 October 2007 08:54 |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
> You brought up something interesting (to me anyway.) If you place
> the
> ELSE earlier in the SWITCH statement, then everything below it is
> executed. If you do the same for a CASE statement then only then
> ELSE is executed. It never occurred to me until I saw your post
> that it was possible to place the ELSE anywhere but at the end.
This is useless and can bring serious headaches...
Both the Case and Switch run from the 1st condition to the last one...
so anything you write below the "else" will never (Case) or always
(Switch) be executed... then there is no need for a Case or Switch
anymore! ... just delete (Case) your code or write it outside of the
Switch block!
Jean
|
|
|
re: Bug in SWITCH - ELSE: statement? [message #56312 is a reply to message #56311] |
Thu, 11 October 2007 08:49  |
Jean H.
Messages: 472 Registered: July 2006
|
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.
The help file is a bit cumbersome to understand. The preceding paragraph
says:
If a match is found, program execution jumps to that statement and
execution continues from that point. Whereas CASE executes at most one
statement within the CASE block, ***SWITCH executes the first matching
statement and any following statements in the SWITCH block***. Once a
match is found in the SWITCH block, execution falls through to any
remaining statements. For this reason, the BREAK statement is commonly
used within SWITCH statements to force an immediate exit from the SWITCH
block.
In other words, If no conditions are met, the Else statement is
applied... but if a condition is met and you are not using a Break
statement, then everything beyond this condition, including the Else
statement, is applied..
Jean
|
|
|