Trying to figure out how to implement "break" type statement in void loop () to no avail. "break" only works with "for" or "while". Below is a crude example.
I could write this differently (check for condition3 before each subsequent operation) but my code and number of conditions/sub-conditions is too long and this will make things even more complicated.
Is there a way to go straight to the beginning of void loop() if condition3.5 is met? thank you.
void loop() {
if condition1==true{}
if condition2==true{}
if condition3==true { //THIS IS UMBRELLA IF STATEMENT THAT HAS LONG LIST OF OPERATIONS.
if condition3.5==true {
condition3 = false; //THIS IS WHERE THE UMBRELLA CONDITION (CONDITION3) BECOMES FALSE AND THE SUBSEQUENT STEPS UNDER THIS OVERARCHING CONDITION SHOULDN'T TAKE PLACE. THIS IS WHERE THE CODE SHOULD GO TO THE BEGINNING OF VOID LOOP ()
break; //UNFORTUNATELY, break DOESN'T WORK SINCE THIS IS NOT for or while STATEMENT.
}
condition3.6
condition3.7
operation3.8
etc.
}
}
}
P.S. I searched this topic quite a bit but all the responses seem to focus on "stopping" void loop() but I am trying to just go straight to the beginning of void loop() and continue from there.
Sorry, I am little dense today and beginner to the arduino/C+. I searched "return" but, based on my interpretation, it is in the context of function returning value (not interrupting current iteration of loop and going to the beginning of a loop). here is another way of asking the same question:
loop() {
1 condition, function, or operation
2 condition, function, or operation
3 condition //if this condition is true then jump back to the beginning of the loop and start from there (do not go through conditions 4, 5 or 6 this time).
4 condition, function, or operation
5 condition, function, or operation
6 condition, function, or operation
}
I could easily do this with lots of if statements but the program is fairly long with lots of different conditions in different points. So, it would be extremely helpful if there was a command to "jump out" of the current iteration of a loop and "jump in" at the beginning
A return command exits a function and returns control to the calling function.
A return command in loop() returns control to the hidden function main() which immediately calls loop() again - hence a return within loop() has the effect of bringing control back to the start of loop()
So, it would be extremely helpful if there was a command to "jump out" of the current iteration of a loop and "jump in" at the beginning
You don't need to, that just happens anyway. When it gets to the end it goes back to the beginning, that's built in, that's why it's called 'loop()', the clue is in the word 'loop'.
I think it's a little bit strange, even if it works. If I had something like this (which hasn't actually ever happened to me...) to do, I would just put a conditional block around the code at the end. That would be a lot less obfuscated.
if condition3.5==true {
condition3 = false;
}
else {
condition3.6
condition3.7
operation3.8
etc.
}
}
}