User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
228
While Statement
Use the while keyword to conditionally iterate a statement. The syntax of the while statement is:
while expression do statement
statement is executed repeatedly as long as expression evaluates true. The test takes place before the statement
is 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 do
begin
s := s + a[i] * b[i];
i := i + 1;
end;
Probably the easiest way to create an endless loop is to use the statement:
while TRUE do ...;
Repeat Statement
The repeat statement executes until the condition becomes true. The syntax of the repeat statement is:
repeat statement until expression
statement is executed repeatedly as long as expression evaluates false. The expression is evaluated after each
iteration, so the loop will execute statement at least once.
Here is an example of calculating scalar product of two vectors, using the repeat statement:
s := 0; i := 0;
...
repeat
begin
s := s + a[i] * b[i];
i := i + 1;
end;
until i = n;