while in conjunction with do repeats a statement as long as a condition evaluates to true. The condition expression is evaluated prior each iteration, determining whether the following block (or single statement) is executed. This is the main difference to a repeat … until-loop, where the block is executed at any rate, but succeeding iterations do not necessarily happen, though.
The following example contains unreachable code:
program whileFalse(input, output, stderr);
while false do
writeLn('never gets printed');
You usually use while-loops where, in contrast to for-loops, a running index variable is not required, the block executed can't be deduced from an index that's incremented by one, or to avoid a break-statement (which usually indicates bad programming style).
program whileDemo(input, output, stderr);
x := 1;
// prints non-negative integer powers of two
while x < high(x) div 2 do
inc(x, x); // x := x + x