Multiple if statements with same conditions

I want my code to execute like this:

void loop()

if (condition_1 true) {
do this
}

if (condition_2 true) {
do this
}

if (condition_3 true) {
do this
delay(1000); //delay 1 sec
}

if (condition_1 true) { //this condition is the same as the condition in the first if statement.
do this
delay(30000); //delay 30 sec, I want the loop to stop for 30 sec before it goes to the first if statement and repeats again.
}

if you have multiple is statement with the same condition, how do you tell the program to differentiate between those two?

You don't. It will execute the top one first, and then the next one, and so on.

Does the program need to differentiate between the two? If there is a need to differentiate between the two, then the two conditions cannot truly be the same, there must be some difference. If they are exactly the same then it would be impossible to differentiate between them, would it not?

if (condition_1 true) {
do this
delay(30000);
}

I hope you understand that during that 30 second delay, if the other conditions become true, your sketch will not detect that and will not take any action?

Hello
Take some time and study the application of the case/switch instruction.

Maybe nested ifs is what you are after? I.e. if some outer condition is met, branch into 2 subconditions and do something different in each case? This can easily be done.

Do you have an actual example of what you are trying to achieve, or is it only a theoretical question?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.