User manual
226
mikoBasic PRO for PIC32
MikroElektronika
Also, you can group values together for a match. Simply separate the items by commas:
select case reg
case 0
opmode = 0
case 1,2,3,4
opmode = 1
case 5,6,7
opmode = 2
end select
Nested switch
Note that the select case statements can be nested – values are then assigned to the innermost enclosing
select case statement.
Iteration Statements (Loops)
Iteration statements let you loop a set of statements. There are three forms of iteration statements in mikroBasic PRO
for PIC32:
- for
- while
- do
You can use the statements break and continue to control the ow of a loop statement. break terminates the statement
in which it occurs, while continue begins executing the next iteration of the sequence.
For Statement
The for statement implements an iterative loop and requires you to specify the number of iterations. The syntax of the
for statement is:
for counter = initial_value to nal_value [step step_value]
statement_list
next counter
counter is a variable which increments with each iteration of the loop. Before the rst iteration, counter is set to
initial_value and will increment until it reaches nal_value. nal_value will be recalculated each time the
loop is reentered.
This way number of loop iterations can be changed inside the loop by changing nal_value. With each iteration,
statement_list will be executed.
initial_value and nal_value should be expressions compatible with counter; statement_list may be
consisted of statements that don’t change the value of the counter.
Note that the parameter step_value may be negative, allowing you to create a countdown.