Usando o while pedimos ao Pascal para repetir "enquanto" a expressão for verdadeira
Sintaxe:
while
begin
end;
Veja o exemplo acima usando while:
program media_notas;
var
NOME: string;
N1, N2, N3, MEDIA: real;
CONT: integer;
begin
CONT:=0;
while CONT<=50 do
begin
CONT:=CONT+1;
read(NOME,N1,N2,N3);
if (N1>=0) and (N2>=0) and (N3>=0) then
begin
MEDIA:=(N1+N2+N3)/3;
writeln('O aluno de nome ',NOME,' tem a média ',MEDIA,' em suas notas ');
end
else
writeln('Não são aceitas notas negativas ');
end;
end;
Referência: <http://pt.wikibooks.org/wiki/Pascal>.