switch case question
Kay C Lan
lan.kc.macmail at gmail.com
Sun Nov 5 03:15:13 EST 2006
On 11/5/06, Dar Scott <dsc at swcp.com> wrote:
>
> The 'switch x' seems to convert x to a string and the 'case y' seems
> to convert y to a string, and then comparisons are made.
Excellent Detective work Dar. It also reinforces a habit I'm trying to
develop when writing switch statements, and that is to always use the
default as a catch for cases I haven't considered:
switch L
case (5)
handler1
break
case (5.0)
handler2
break
case ("5")
handler3
break
case ("5"&"."&"0")
handler4
break
default
answer "Switch statement error" & return &
"Handler: myHandler" & return &
"Paramater L: " & L
exitGracefully
end switch
Obviously, from what you're saying, handler3/4 would never run, but
more importantly, if 5. (decimal point byt no zero) got into L, I
should get immediate feedback that I haven't correctly taken it into
account in my switch structure.
I've wasted a lot of time stepping through scripts that don't do what
they're suppose to do and often it is because I've added a feature to
and old stack and don't realise that this new feature now puts new
values into properties that get checked by some buried switch
structure which completely ignores it because it was never part of the
original cases considered. Using default as a catch nails it
instantly.
Hope that helps someone:-)
More information about the use-livecode
mailing list