Lecture 11: Loops II: While ... Do and Repeat ... Until |
The general format of the while-do loop is
|
|
program code
PROGRAM WhileExample; Var x: real; begin
|
output
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 |
|
|
program code
x := 100; repeat writeln('Ajax'); x := x + 1; until (x>10); |
program code
x := 100; while (x<=10) do begin writeln('Ajax'); x := x + 1; end; |
program code
for i := 100 to 10 do begin writeln('Ajax'); end; |
output
Ajax |
output
|
output
|
|
|
for i := 1 to 10 do
for k := 1 to 10 do begin for k := 1 to 10 do writeln('Hello'); end; |
for k := 1 to 10 do
begin i := k; repeat j := i-1; while (j<10) do begin end; {end of for} i := i + 1; until i>20; {end of repeat-until} j := j + 1; end; {end of while-do} Good indentation of your program will
|