program whileloop2; { This program demonstrates a "while" loop. It continually asks the user to enter a number until that number is 0. } var n : integer; { the number entered by user } begin write('Enter a number: '); readln(n); while n <> 0 do begin writeln('The number you entered is ', n); { Ask for another number } write('Enter a number: '); readln(n); end; end.
Below we show a compilation and run of the program.
% pc whileloop2.p % a.out Enter a number: 4 The number you entered is 4 Enter a number: 7 The number you entered is 7 Enter a number: 0