User manual

Table Of Contents
250
mikoC PRO for PIC32
MikroElektronika
Expression Statements
Any expression followed by a semicolon forms an expression statement:
expression;
The mikroC PRO for PIC32 executes an expression statement by evaluating the expression. All side effects from this
evaluation are completed before the next statement starts executing. Most of expression statements are assignment
statements or function calls.
A null statement is a special case, consisting of a single semicolon (;). The null statement does nothing, and therefore
is useful in situations where the mikroC PRO for PIC32 syntax expects a statement but the program does not need one.
For example, a null statement is commonly used in “empty” loops:
for (; *q++ = *p++ ;); /* body of this loop is a null statement */
Selection Statements
Selection or ow-control statements select one of alternative courses of action by testing certain values. There are two
types of selection statements:
- if
- switch
If Statement
The if statement is used to implement a conditional statement. The syntax of the if statement is:
if (expression) statement1 [else statement2]
If expression evaluates to true, statement1 executes. If expression is false, statement2 executes. The
expression must evaluate to an integral value; otherwise, the condition is ill-formed. Parentheses around the
expression are mandatory.
The else keyword is optional, but no statements can come between if and else.
Nested If statements
Nested if statements require additional attention. A 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) */