If statements vs case
ambassador at fourthworld.com
Mon Feb 26 15:39:45 EST 2007
Hershel Fisch wrote:
> On 2/26/07 2:27 PM, "Shao Sean" <shaosean at wehostmacs.com> wrote:
>> 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)
> Sorry, what do you mean that IF-ELSE-IF is always evaluated?
> Dosn't the "else" break it?
> end if
> End if
I believe Shao Sean is correct, at least as far as the initial condition
Of course when nesting if the first one is false then the nested ones
won't be evaluated.
Also, Rev's if is fairly well optimized, so in a single if with multiple
conditions like this:
if (1=2) AND ("r" is in "richard") then
...the second test won't be tried since the first one isn't true.
This can be helpful to keep in mind when writing multi-condition ifs,
putting the least likely one in front to minimize subsequent processing.
Managing Editor, revJournal
Rev tips, tutorials and more: http://www.revJournal.com
More information about the Use-livecode