ABL electronic PIC12 Personal Computer User Manual


 
Iteration Statements
Iteration statements let you loop a set of statements. There are three forms of itera-
tion statements in C: while, do, and for.
While Statement
Use the
while keyword to conditionally iterate a statement. Syntax of while
statement is:
while (
expression
)
statement
The
statement
executes repeatedly until the value of expression is false. The test
takes place before
statement
executes. Thus, if
expression
evaluates to false
on the first pass, the loop does not execute.
Parentheses around
expression
are mandatory.
Here is an example of calculating scalar product of two vectors, using the
while
statement:
int s = 0, i = 0;
while (i < n) {
s += a[i] * b[i];
i++;
}
Note that body of a loop can be a null statement. For example:
while (*q++ = *p++);
MikroElektronika:
Development
tools
-
Books
-
Compilers
11 9
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...