break and continue StatementsThese statements are only allowed inside a loop statement body. The
break statement exits a loop statement body prematurely. The
continue statement skips any remaining code within the loop
statement body and jumps back to the top of the loop.
pinMode(2, INPUT);
// Exit loop upon GPIO input high
for (;;) // Infinite loop
{
if (digitalRead(2)) break;
}
// Stop an elevator at every floor except unlucky floor 13
for (int Floor = 1; Floor <= 20; Floor++)
{
if (i == 13) continue;
StopAt(Floor);
}
Fun Fact: The Otis Elevator Company estimated in 2002 that 85% of buildings taller than 12 stories and containing an Otis elevator do not have a 13th floor.