Loops/Downward for: Difference between revisions

m
→‎{{header|ALGOL-M}}: added workaround
m (→‎{{header|ALGOL-M}}: added workaround)
 
Line 345:
=={{header|ALGOL-M}}==
Sadly, ALGOL-M's FOR statement does not allow a negative value
for STEP, so in order to count down we either have to use a WHILE loop if we wish to count down.
or move the subtraction into the body of the FOR loop
<syntaxhighlight lang="ALGOL">
begin
Line 351 ⟶ 352:
integer i;
 
write("First approach :");
i := 10;
while (i >= 0) do
begin
writeon(i);
i := i - 1;
end;
 
write("Second approach:");
for i := 0 step 1 until 10 do
writeon(10-i);
 
end
Line 362 ⟶ 368:
{{out}}
<pre>
First approach : 10 9 8 7 6 5 4 3 2 1 0
Second approach: 10 9 8 7 6 5 4 3 2 1 0
</pre>
 
13

edits