User manual

226
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Assignment Statements
Assignment statements have the following form:
variable = expression
The statement evaluates expression and assigns its value to variable. All the rules of implicit conversion are
applied. Variable can be any declared variable or array element, and expression can be any expression.
Do not confuse the assignment with relational operator = which tests for equality. mikroBasic PRO for dsPIC30/33 and
PIC24 will interpret the meaning of the character = from the context.
Conditional 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
- select case
If Statement
Use the keyword if to implement a conditional statement. The syntax of the if statement 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; otherwise, the condition is ill-formed. The else keyword with an
alternate block of statements (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