Control Statements

Up until this chapter, our source code has been relatively straightforward. The Arduino microcontroller reads the lines of code in our sketches from the top of the code until it reaches the end at the bottom, and, when there are no more commands to execute, will bounce back to the top of the loop() function and start over again. The order or direction in which code is executed is called program flow and the ability to alter this order of executing commands is something called flow control.

There are two kinds of statements available in Arduino C for controlling program flow: conditional statements that make decisions based on whether or not a condition is true and iterative statements that perform things a certain number of ...

Get Beginning Arduino Programming now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.