Wikia

Borland Pascal Wiki

WHILE...DO

Talk0
35pages on
this wiki

WHILE...DO — is a Turbo Pascal cycle operator.

ExamplesEdit

WHILE <condition> DO <operator>

where <condition> - is the expression of logic type (True / False).
<operator> - any pascal operator.

If the expression of <condition> is true then <operator> is being performed, after then expression of the <condition> is calculated all over as well as its checking. If <condition> has value FALSE , operator WHILE stops its work.

var
x, n1 : integer;
begin
writeln('type x');
readln(x);
n1 := 5;
While x < 10 Do
begin
x := x + n1;
writeln(x);
end
end.

If you type 1 (x) answer will be:
1 (it has stored the value of x when at readln(x) - it's the value of x when the program had just started and hasn't passed the latter part of the code)
6 (then 1 + 5(n1))
11 (as from previous x := 6, it started from this value at while x < n do and when it (x) tries to pass again at while x < do it won't satisfy the condition, as 11 < 10)

You can also trace the steps (debug) if you press F8.

Around Wikia's network

Random Wiki