PASCAL


  ITERATIVE INSTRUCTIONS

Iteration (Latin iteratio – repetition) – repetition activity (usually multiple) the same instruction (or multiple instructions) in a loop.


  LOOP „for”

   for variable:=initial_value to [down to] final_value do instruction;


Example:

     for k:=1 to 2010 do writeln('Kwidzyn');

The instruction will print 2018 "Kwidzyn" inscriptions, each in a separate line. The variable k is of the total type and is incremented by 1 after each loop run.

     for n:=1 to 10 do write(2*n,', ');

will print a sequence of numbers    2, 4, 6, 8, 10, 12, 14, 16, 18, 20,

The passage of the loop is carried out by means of an iterative variable. First the initial value is given to it, then it is checked if it does not exceed the final value, the given instruction is executed, finally the iterative variable (so called loop counter) is increased by 1 and the actions are repeated
The control variable can also be of the character type.
Example:

   var
     zn: char;
   begin
     for zn:='a' to 'z' do writeln(z,'–',ord(zn));
     readln;
   end.

On the screen we will see the letters 'a' to 'z' and their ASCII codes.