Forum Discussion
Feb 22, 2007
Multiple consecutive "if" statements are treated as separate conditional statements. So each statement will be evaluated and if the condition test is non-zero, then the containing code block will be executed. An "elseif" and "else" are part of a "if" block and are only evaluated and subsequently processed if a previous condition has a non-zero value. In the examples you cited, the first could easily have used a single if with elseif's and that would have likely been more efficient as all "if" tests would not necessarily need to be executed.
So, for a general rule of thumb. If your test is "if this do this, or that do that" then use a single if statement with elseif's and an else. If your test is "if this do this, if that do that", then use multiple if statements.
Make sense? It's really just a question of how you want the logical flow of your code to go.
-Joe