User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
225
If Statement
Use the keyword if to implement a conditional statement. The syntax of the if statement has the following form:
if expression then statement1 [else statement2]
If expression evaluates to true then statement1 executes. If expression is false then statement2 executes.
The expression must convert to a boolean type; otherwise, the condition is ill-formed. The else keyword with an
alternate statement (statement2) is optional.
There should never be a semicolon before the keyword 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 then
if expression2 then statement1
else statement2
The compiler treats the construction in this way:
if expression1 then
begin
if expression2 then statement1
else statement2
end
In order to force the compiler to interpret our example the other way around, we have to write it explicitly:
if expression1 then
begin
if expression2 then statement1
end
else statement2
Case Statement
Use the case statement to pass control to a specic program branch, based on a certain condition. The case statement
consists of a selector expression (a condition) and a list of possible values. The syntax of the case statement is:
case selector of
value_1 : statement_1
...
value_n : statement_n
[else default_statement]
end;