If statements vs case

Shao Sean shaosean at wehostmacs.com
Mon Feb 26 14:27:05 EST 2007


There are differences between SWITCH and IF-ELSE-IF statements in other 
languages, but in regards to Revolution someone from the engine team 
would be best to answer it.

In many languages SWITCH statements are converted into a hash table for 
much quicker lookups and using a SWITCH once or twice is slower than 
using an IF-ELSE-IF statement due to the SWITCH statement getting 
hashed, but using the same SWITCH statement multiple times will 
increase the speeds.
Also, because of the fact that an IF-ELSE-IF statement is _always_ 
evaluated, they can never be faster than a SWITCH statement (they can 
be just as fast, but never faster)

There are a few other differences between SWITCH and IF-ELSE-IF 
statements that do not seem to apply to  Revolution due to the fact you 
can use SWITCH statements just like an IF-ELSE-IF statement. Example;

switch
case (tLUET < 42)
   # do something
   break
case (tLUET > 42)
   # do something
   break
case (tLUET = 42)
   # do something
   break
default
   # do something
   break
end switch

The above would usually need to be done with a IF-ELSE-IF statement 
but, as you can see, Revolution can do it as a SWITCH statement.

-Sean




More information about the Use-livecode mailing list