Forum Discussion
Dan_103700
Mar 11, 2011Nimbostratus
Nested Conditionals and NOT conditionals
Hi there,
I've been meaning to ask for awhile how to do nested conditionals and use a "not" operator in iRules.
I frequently end up writing iRules that look like this:
if { $foo starts_with "bar" } {
Do Nothing
} else {
pool foo_pool
}
Would I get the same thing with just:
if { not $foo starts_with "bar" } {
pool foo_pool
}
Also, is it possible to do nested conditionals... something like:
if { {$foo starts_with "bar" or $bar ends_with "foo"} and {$baz == 5} } {
And ideally, combine these 2 to get something like:
if { { {not $foo starts_with "bar"} or $bar ends_with "foo"} and {$baz == 5} } {
I guess if I take the time to learn the operator precedence and how conditional comparisons evaluate from left to right, I wouldn't need the extra nesting. Still, as a programmer, I've always found value in adding extra parenthesis to make conditional logic easier to read. Hopefully, there's some similar syntax in Irules/TCL to do this because trying to program without the extra braces/parenthesis makes my head hurt.
Thanks!
-Dan
- hoolioCirrostratusHi Dan,
if { not ($foo starts_with "bar") } { pool foo_pool }
- Chris_MillerAltostratusColin did a good overview on nested conditionals here - http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/255/iRules-101--13--Nested-Conditionals.aspx
- hoolioCirrostratusTCL operator precedence should be the same as most other languages. So the ! or not takes precedence over the starts_with string evaluation.
- Dan_103700NimbostratusGreat info. I have a feeling I'll be cleaning up some of my messier work, come Monday. Thanks.
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