Forum Discussion
Ron_Kim_110696
Feb 22, 2007Nimbostratus
Using "elseif" and "if" statements
Sorry if this is a duplicate, but I could not find a post regarding this question.
Here are two examples.
Uses multiple "if":
http://devcentral.f5.com/wiki/default.aspx/iRule...
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
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects