Loops/Downward for: Difference between revisions

Content added Content deleted
m (→‎{{header|ALGOL-M}}: added workaround)
 
Line 345: Line 345:
=={{header|ALGOL-M}}==
=={{header|ALGOL-M}}==
Sadly, ALGOL-M's FOR statement does not allow a negative value
Sadly, ALGOL-M's FOR statement does not allow a negative value
for STEP, so we have to use a WHILE loop if we wish to count down.
for STEP, so in order to count down we either have to use a WHILE loop
or move the subtraction into the body of the FOR loop
<syntaxhighlight lang="ALGOL">
<syntaxhighlight lang="ALGOL">
begin
begin
Line 351: Line 352:
integer i;
integer i;


write("First approach :");
i := 10;
i := 10;
while (i > 0) do
while (i >= 0) do
begin
begin
writeon(i);
writeon(i);
i := i - 1;
i := i - 1;
end;
end;

write("Second approach:");
for i := 0 step 1 until 10 do
writeon(10-i);


end
end
Line 362: Line 368:
{{out}}
{{out}}
<pre>
<pre>
10 9 8 7 6 5 4 3 2 1
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>
</pre>