Continue evaluation regardless of outcome

I may be asking something simple/foolish here, but I’m not a coder by nature. I think I’m failing to say something properly when trying to search and find something as I’m sure others have done this before.

I’d like to put together a block of code similar to what is shown below as an example. But what I’d like to do is not stop the execution once it finds a true value. I’d like it to iterate through all the If, ElseIf blocks, and execute ANY that match.

rule "Sample Rule"
when item_name changed
then
  if(item_name1.state == ON){
    sendCommand(item_x, ON)
    }
  else if(item_name2.state == ON){
    sendCommand(item_y, ON)
    }
  else{
    logInfo("name", "No cases met, exiting")
end

My goal here is if something changed, I want to validate multiple other cases to do something, but I don’t want the usual activity to be first case met, we execute and exit the code block. I’d like to check the first If block, execute if true, second else if block, execute if true, etc. I don’t want to get into multiple nested if situations where I have to list all the possible outcomes to execute everything beneath the first if as that looks and gets messy to understand.

What you are describing are either nested ifs like:

if(item_name1.state == ON){
sendCommand(item_x, ON)
if(item_name2.state == ON){
sendCommand(item_y, ON)
}
}

or separated ifs like:

if(item_name1.state == ON){
sendCommand(item_x, ON)
}
if(item_name2.state == ON){
sendCommand(item_y, ON)
}

In the first case the second if will only be prosecuted if the first one is true, in the second case both will be run. Which one do you want?
Sorry for the bad formatting, I’m writing on a tablet.

No problem at all @opus, I appreciate you hopping in to help illustrate.

Ok I think I get your first example, as that’s what I didn’t want. I want to make sure that EACH of the IF statements get evaluated and executed if True separately from each other. Aka if the second one is true but first is not, only the second will execute.

I think your second explanation is what I’m aiming for, but I guess I’m surprised to find I can just put a bunch of IF statements in. I thought I’d need to use else if after the first if. But it seems you’re indicating multiple if statements, will each evaluate.

And if I wanted to log something as the “else” case, I’d have to do something more complicated like storing a value for an else statement on all IF statements and correlate the total afterward (something like an increment counter, then if counter = X, then log info). But that’s complicating things and honestly not the biggest concern.

Reading your second explanation I get it, you need the second example.
As for the logging in each else case, yes that would be needed in each separated if clause. You could get around that by writing something called in here “lambda expression”, that is basically writing a reusable routine. I would suggest you try it first in the lengthy way.