Datasheet

switch (phase) {
case 0: Lo(); break;
case 1: Mid(); break;
case 2: Hi(); break;
default: Message("Invalid state!");
}
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 iter-
ation statements in the mikroC PRO for AVR:
- 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 first pass, the loop does not execute. Note that parentheses around expres-
sion
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++);
212
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5