Sure,
The arduino has a hidden function in the core called main ( a standard c++ entry point ), it is the first* function to run, it has these few lines:
int main(){
init();
setup();
while( true ){
loop();
}
}
init(); sets up the arduino timers/pwm/other stuff
setup(); calls the
setup function you define in your sketch.
loop(); this also calls your sketch
loop function, notice it is inside a
never ending loop.
Now the code I provided:
loop(){
//return on LOW, loop will automatically restart.
if( Variable != HIGH ) return;
while( Variable == HIGH ){
//Do stuff while true.
}
}
As this function is called in an infinite loop, it will repeat as soon as it finishes.
if( Variable != HIGH ) return; This will cause the function to exit when the variable is low.
When HIGH, the code is allowed to flow into the '
while( Variable == HIGH ){' loop, which will not exit until the variable goes LOW.
As the loop function continually loops, it will return to the if statement constantly exiting the function until another HIGH