User manual

mikroBasic PRO for PIC32
MikroElektronika
227
If nal_value is a complex expression whose value can not be calculated in compile time and number of loop
iterations is not to be changed inside the loop by the means of nal_value, it should be calculated outside the for
statement and result should be passed as for statement’s nal_value. statement_list is a list of statements
that do not change the value of counter.
Here is an example of calculating scalar product of two vectors, a and b, of length 10, using the for statement:
s = 0
for i = 0 to 9
s = s + a[i] * b[i]
next i
Endless Loop
The for statement results in an endless loop if nal_value equals or exceeds the range of the counter’s type.
While Statement
Use the while keyword to conditionally iterate a statement. The syntax of the while statement is:
while expression
statements
wend
statements are executed repeatedly as long as expression evaluates true. The test takes place before statements
are executed. Thus, if expression evaluates false on the rst pass, the loop does not execute.
Here is an example of calculating scalar product of two vectors, using the while statement:
s = 0
i = 0
while i < n
s = s + a[i] * b[i]
i = i + 1
wend
Probably the easiest way to create an endless loop is to use the statement:
while TRUE
‘ ...
wend