# if syntax help!

**URL:** <https://community.f5.com/t/if-syntax-help/24005>\
**Category:** Technical Forums\
**Tags:** irules, devops, application-delivery, irule-editor\
**Created:** [February 4, 2007, 2:50pm UTC](https://community.f5.com/t/if-syntax-help/24005 "2007-02-04T14:50:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kai\_wang\_48807](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@kai\_wang\_48807](https://community.f5.com/u/kai_wang_48807)\
**Post date:** [February 4, 2007, 2:50pm UTC](https://community.f5.com/t/if-syntax-help/24005/1 "2007-02-04T14:50:38Z")

</div>

1. Whether the if could be nested in iRule?

E.g if {} {

if {} {

}

elseif {} {

}

}

2. Whether the when could be nested in iRule?

E.g when xx {

when xx {

}

}

Thanks!

Kai

---

<div class="post-metadata">

**Author:** ![Joe\_Pruitt](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/joe_pruitt/32/8438_2.png) [@Joe\_Pruitt](https://community.f5.com/u/Joe_Pruitt)\
**Post date:** [February 5, 2007, 4:31am UTC](https://community.f5.com/t/if-syntax-help/24005/2 "2007-02-05T04:31:27Z")

</div>

Nested conditional statements are absolutely legal.

So, this IS legal:

```tcl
when HTTP_REQUEST {
  if { condition_1 } {
    if { condition_2 } {
      if { condition_3 } {
      } elseif { condition_4 } {
         and on and on an on...
      } else {
      }
    } elseif { condition_5 } {
    } else {
    }
  } elseif { condition_6 } {
  } else {
  }
}

```

But the when statement is a special F5 extension to TCL that allows for event triggering. Think of it like a function in C. These are only allowed at the outermost scope within an iRule.

This is NOT legal:

```tcl
when HTTP_REQUEST {
  when HTTP_RESPONSE {
  }
}

```

But, this IS legal:

```tcl
when HTTP_REQUEST {
  ...
}
when HTTP_RESPONSE {
  ...
}

```

-Joe
