comment Control structures in Algol 60;
comment Section 1.4;
begin
integer array a[1:10];
comment Counted loops.;
begin
integer i;
for i := 1 step 1 until 10 do
a[i] := 10 - (i - 5) * (i - 5)
end;
begin
integer i, m, p;
m := -1000; p := 0;
for i := 1 step 1 until 10 do
if a[i] >= m then begin p := i; m := a[i] end;
outstring(1, "Finding the maximum of an array:\n");
print(m);
print(p)
end;
begin
integer i;
for i := 1 step 1 until 10 do
a[i] := i * i;
end;
comment While loop with forward goto.;
begin
integer x;
for x := 36 step 1 until 37 do
begin
integer low, high, mid;
low := 1; high := 10;
for mid := low + (high - low) / 2 while low <= high do begin
if x < a[mid] then high := mid - 1
else if x > a[mid] then low := mid + 1
else goto FOUND
end;
NOTFOUND:
outstring(1, "Binary search: not found\n");
goto DONE;
FOUND:
outstring(1, "Binary search: found\n");
print(mid);
DONE:
end
end
end