A r t i c l e s
Navigation

Note: This Wiki is
outdated, personal views
may have changed.
L505 A.I. bot is dead
long live THX 1138

M a i n P a g e

D i r e c t o r y

While vs Repeat Differences


To tell the difference between a repeat versus a while loop, consider the following program. The two outputs will be different:
program Project2;
{$APPTYPE CONSOLE}
uses SysUtils;

var
  i: integer;
  x: char;
  s: string[10];
begin
  s:='5blackcats';
  i:= 0;
  x:='t';
  writeln('While loop output:');
  while (x <> 't') do
  begin
    inc(i);
    x:= s[i];
    write(s[i]);
  end;

  s:='5blackcats';
  i:= 0;
  x:='t';
  writeln;
  writeln('Repeat loop output:');
  repeat
    inc(i);
    x:= s[i];
    write(s[i]);
  until x = 't';

  readln;
end.
The while loop checks that x is equal t and stops immediately. The repeat loop runs through the first time without checking x first, because it checks x inside the loop only.

About
Note: This Wiki is outdated, personal views may have changed.

This wiki contains info on life, health, humans, nature, programming, database, fads, paradigms, poems, principles, theories.

Articles may contain statements which some may find helpful and encouraging, or even discouraging.

Beware, I believe in the Grand Justice system.
_ _ _