ABL electronic PIC16 Personal Computer User Manual


 
All the expressions are optional. If
condition-exp
is left out, it is assumed to be
always true. Thus, “empty” for statement is commonly used to create an endless
loop in C:
for ( ; ; ) {...}
The only way to break out of this loop is by means of break statement.
Here is an example of calculating scalar product of two vectors, using the
for
statement:
for (s = 0, i = 0; i < n; i++) s += a[i] * b[i];
You can also do it like this:
/* valid, but ugly */
for (s = 0, i = 0; i < n; s += a[i] * b[i], i++);
but this is considered a bad programming style. Although legal, calculating the
sum should not be a part of the incrementing expression, because it is not in the
service of loop routine. Note that we used a null statement (
;) for a loop body.
MikroElektronika:
Development
tools
-
Books
-
Compilers
12 1
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...