Arduino - for loop


Advertisements

A for loop executes statements a predetermined number of times. The control expression for the loop is initialized, tested and manipulated entirely within the for loop parentheses. It is easy to debug the looping behavior of the structure as it is independent of the activity inside the loop.

Each for loop has up to three expressions, which determine its operation. The following example shows general for loop syntax. Notice that the three expressions in the for loop argument parentheses are separated with semicolons.

for loop Syntax

for ( initialize; control; increment or decrement) {
   // statement block
}

Example

for(counter = 2;counter <= 9;counter++) {
   //statements block will executed 10 times
}

for loop Execution Sequence

For Loop
arduino_loops.htm
Advertisements