Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
CONDITIONAL STATEMENTS
Conditional or selection statements select from alternative courses of action by test-
ing certain values. There are two types of selection statements:
- if 
- select case 
IF STATEMENT
Use the keyword if to implement a conditional statement. The syntax of the if state-
ment has the following form:
if expression then
statements
[
else
other statements]
end if
When 
expression
evaluates to true, 
statements
execute. If 
expression
is false,
other statements
execute. The 
expression
must convert to a boolean type; oth-
erwise, the condition is ill-formed. The 
else
keyword with an alternate block of state-
ments (
other statements
) is optional.
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
end 
if
end 
if
The compiler treats the construction in this way:
if expression1 then
if expression2 then
statement1
else
statement2
end if
end if
153
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5