PASCAL


  ITERATIVE INSTRUCTIONS.

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


  LOOP „repeat”

   repeat instructions; until condition;


We use it when we do not know the exact number of repetitions, but we want the given instruction to be executed at least once. The instructions are executed as long as the given condition is false, and when it is fulfilled, the repetition ends.
Examples:

  sum:=0; n:=0;
  Repeat
    write ('Enter a number (0 ends input) )');
    readln (x);
    if x<>0 then
   begin
   sum:=sum+x; n:=n+1;
   end;
  Until x=0;
 mean:=sum/n;
  writeln('Mean =',mean:0:3);

The program calculates the sum of unknown number of numbers.
The summation ends when the number 0 is given.



  write('Enter the final number ');
  readln(num);
  sum:=0;
  repeat
    sum:=sum+num;
    num:=num-1;
  until num=0;
  writeln('Sum=',sum);

The program calculates the sum of integers 1+2+3+...+final_number.