switch case question
Dar Scott
dsc at swcp.com
Sat Nov 4 13:50:16 EST 2006
On Nov 4, 2006, at 10:56 AM, Tereza Snyder wrote:
>> That looked suspicious. Sure enough, a number 6 will match a
>> literal 6 in a case, but a string "6.0" will not match a literal 6
>> in a case. A string "6.0" will match a 6.0 case. A number 6 will
>> not match a 6.0 in the case.
>
>
> To be clear: these DO match in an if? or not?
Good question!
Yes. If both values are the result of arithmetic or looks like a
number (what I call numeral) including E notation and 0x notation,
then a numerical comparison is done with 'is' and '='. The 'if' uses
that '=' operator, so that will work with numbers (numeral or the
result of arithmetic).
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. A numerical
literal is a string in this case. That is, it looks as though 'case
5.0' is the same as 'case "5.0"'.
So, a 'switch' might not be equivalent to a similar 'if'.
The 'switch' does look at caseSensitive and does work with NUL
characters (Rev null).
Is this interesting behavior of 'switch' a feature or a bug? Or is
this already in the docs?
Dar
--
**************************************
Dar Scott
Dar Scott Consulting and Dar's Lab
8637 Horacio Place NE
Albuquerque, NM 87111
Lab, office, home: +1 505 299 9497
Fax: call above first
Skype: ask
http://www.swcp.com/dsc
dsc at swcp.com
Computer programming
**************************************
More information about the use-livecode
mailing list