Forum Discussion

Brian_Moore_603's avatar
Brian_Moore_603
Icon for Nimbostratus rankNimbostratus
Mar 05, 2012

Does iRule programming use "short circuit logic"?

I have an irule that we developed today and we used a couple of operators and was wandering if the programming logic will use a term called "short circuiting" so that the irule didn't run through processing something it already knew about further up in the syntax.

 

 

Melloyellow

1 Reply

  • Hi Brian,

    Yes TCL and iRules use short circuit logic:

    when RULE_INIT {
    if { 0 && $nonexistentvariable} {
    log local0. "got here"
    } else {
    log local0. "short circuited"
    }
    }

    < RULE_INIT>: short circuited

    Compare the output with || logic to hit the nonexistent variable:

    when RULE_INIT {
    if { 0 || $nonexistentvariable} {
    log local0. "got here"
    } else {
    log local0. "short circuited"
    }
    }

    TCL error: short_circuit_rule < RULE_INIT> - can't read "nonexistentvariable": no such variable while executing "if { 0 || $nonexistentvariable} { log local0. "got here" } else { log local0. "short circuited" }"

    If you want to exit out of a specific iRule event for the current request only, you can use the return command:

    https://devcentral.f5.com/wiki/iRules.return.ashx

    And you have break and continue for loops:

    http://www.tcl.tk/man/tcl8.4/TclCmd/break.htm

    http://www.tcl.tk/man/tcl8.4/TclCmd/continue.htm

    Or do you have a more specific example you're thinking of?

    Aaron