Datasheet

For Statement
The for statement implements an iterative loop and requires you to specify the num-
ber of iterations. The syntax of the for statement is:
for counter := initial_value to final_value do statement
// or
for counter := initial_value downto final_value do statement
counter
is a variable which increments (or decrements if you use downto) with each
iteration of the loop. Before the first iteration,
counter is set to initial_value and
will increment (or decrement) until it reaches final_value. With each iteration,
statement will be executed.
initial_value and final_value should be expressions compatible with count-
er; statement
can be any statement that does not change the value of counter.
Here is an example of calculating scalar product of two vectors, a and b, of length
n, using the for statement:
s := 0;
for i := 0 to n-1 do
s := s + a[i] * b[i];
Endless Loop
The for statement results in an endless loop if final_value equals or exceeds the
range of the counter’s type.
More legible way to create an endless loop in Pascal is to use the statement while
TRUE do.
168
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroPASCAL PRO for AVR
CHAPTER 5