mikroC
making it simple...
Nested if statements
mikroC - C Compiler for Microchip PIC microcontrollers
Nested if statements require additional attention. General rule is that the nested conditionals are parsed starting from the innermost conditional, with each else bound to the nearest available if on its left:
if (expression1) statement1 |
|
|
|
| ||
else | if (expression2) |
|
|
|
|
|
if (expression3) statement2 |
|
|
|
| ||
else statement3 | /* this | belongs | to: if | (expression3) | */ | |
else | statement4 | /* this | belongs | to: if | (expression2) | */ |
Note: The #if and #else preprocessor statements (directives) look similar to the if and else statements, but have very different effects. They control which source file lines are compiled and which are ignored. See Preprocessor for more information.
Switch Statement
Use the switch statement to pass control to a specific program branch, based on a certain condition. Syntax of switch statement is:
switch (expression) {
case
.
.
.
case
[default : statement;]
}
First, the expression (condition) is evaluated. The switch statement then compares it to all the available
Parantheses around expression are mandatory.
.
|
| page |
|
MikroElektronika: Development tools - Books - Compilers | 117 | ||
|
|