User manual

Table Of Contents
252
mikoC PRO for PIC32
MikroElektronika
Nested switch
Conditional switch statements can be nested labels case and default are then assigned to the innermost
enclosing switch statement.
Iteration Statements (Loops)
Iteration statements allows to loop a set of statements. There are three forms of iteration statements in the mikroC PRO
for PIC32:
- while
- do
- for
While Statement
The while keyword is used to conditionally iterate a statement. The syntax of the while statement is:
while (expression) statement
The statement executes repeatedly until the value of expression is false. The test takes place before statement
is executed. Thus, if expression evaluates to false on the rst pass, the loop does not execute. Note that 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 the loop can be a null statement. For example:
while (*q++ = *p++);
Do Statement
The do statement executes until the condition becomes false. The syntax of the do statement is:
do statement while (expression);
The statement is executed repeatedly as long as the value of expression remains non-zero. The expression is
evaluated after each iteration, so the loop will execute statement at least once.
Parentheses around expression are mandatory.