Description
The for
statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The for
statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins.
Syntax
for (initialization; condition; increment) {
// statement(s);
}
Parameters
initialization
: happens first and exactly once.
condition
: each time through the loop, condition
is tested; if it’s true
, the statement block, and the increment is executed, then the condition is tested again. When the condition becomes false
, the loop ends.
increment
: executed each time through the loop when contition
is true.