SPC  Version 0.9.5
 All Files Functions Groups Pages
The for statement

Another kind of loop is the for loop.

This type of loop allows automatic initialization and incrmementation of a counter variable. It uses the syntax shown below.

for(statement1 ; condition ; statement2) body

A for loop always executes statement1, and then it repeatedly checks the condition. While the condition remains true, it executes the body followed by statement2. The for loop is equivalent to the code shown below.


Frequently, statement1 sets a loop counter variable to its starting value. The condition is generally a relational statement that checks the counter variable against a termination value, and statement2 increments or decrements the counter value.

Here is an example of how to use the for loop:

for (int i=0; i<8; i++)
NumOut(0, LCD_LINE1-i*8, i);