If statements vs case
Shao Sean
shaosean at wehostmacs.com
Wed Feb 28 19:45:19 EST 2007
> Sorry, what do you mean that IF-ELSE-IF is always evaluated?
If you have a 20 line nested IF-ELSE-IF statement and the one that
matches your current situation is the 20th one, the previous 19 are
evaluated (thankfully Rev uses some short-circuited methods to speed it
up)
In a SWITCH statement the engine/compiler converts the CASE statements
into a hashed lookup table (think fast) and as such when the SWITCH
statement is evaluated it just quickly looks up the code to run in the
hash table.
As I mentioned in my first posting, if you're only using the IF-ELSE-IF
statement a few times, you don't have to wait for the SWITCH lookup
table to be hashed (adding overhead the first time a SWITCH statement
is called)
Also mentioned in my first posting, how much of this applies to
Revolution in general only they know, as Revolution allows you to some
weird things with the SWITCH statements that you couldn't do in other
languages (apparently a lot of languages the result of the SWITCH
statement can only be an integer)
-Sean
More information about the use-livecode
mailing list