Forum Discussion
morris
Nimbostratus
Oct 06, 2020iRules command: Switch vs If
I saw the article in https://devcentral.f5.com/s/articles/irules-101-04-switch saying Switch is a higher performing command and run faster than If command. Why is that so?
- Oct 06, 2020
Yes Morris. That's right.
If-statement with 3 conditions (and default).
if { $bla eq "one" } { # do something } elseif { $bla eq "two" } { # do something } elseif { $bla eq "three" } { # do something } else { # do something }Switch-statement with 3 conditions (and default).
switch $bla { "one" { # do something } "two" { # do something } "three" { # do something } default { # do something } }Don't forget to mark my answer as the best the help me for the contribution.
Regards,
Dario.
Dario_Garrido
Noctilucent
Oct 06, 2020Yes Morris. That's right.
If-statement with 3 conditions (and default).
if { $bla eq "one" } {
# do something
} elseif { $bla eq "two" } {
# do something
} elseif { $bla eq "three" } {
# do something
} else {
# do something
}Switch-statement with 3 conditions (and default).
switch $bla {
"one" {
# do something
}
"two" {
# do something
}
"three" {
# do something
}
default {
# do something
}
}Don't forget to mark my answer as the best the help me for the contribution.
Regards,
Dario.
morris
Nimbostratus
Oct 07, 2020Thanks!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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