Exit rule with return false

I know what you mean and agree that this is often a good idea. Let me give just one example I ran into the other day.

rule "Entrance door monitoring"
when
    Item Entrance_Door changed to OPEN
then
    if (Night_State.state == ON) {
        // 30 lines of wild code
    }
end

Alternative:

    if (Night_State.state != ON) break or return
    // 30 lines of wild code

Of course in reality this situation can become worse if multiple conditions or multiple steps are involved. I’m sure you can think of similar ones :wink: If the alternative is a better solution is pure personal preference I’d say.


@sjka

  • if (something) return false - Validator: “Void functions cannot return a value.”
  • if (something) return void - Validator: “Void functions cannot return a value.”
  • if (something) return - Validator: “Void functions cannot return a value.”
  • if (something) break - Validator is please but the rule will yield an error: “An error occurred during the script execution: The name ‘break’ cannot be resolved to an item or type.”
1 Like