Loops/Downward for: Difference between revisions

m
→‎{{header|ALGOL-M}}: added workaround
(added 8080 assembly example)
m (→‎{{header|ALGOL-M}}: added workaround)
 
(17 intermediate revisions by 9 users not shown)
Line 179:
;
end
</syntaxhighlight>
</systaxhighlight>
{{out}}
<pre>
Line 342:
print((i,new line))
OD</syntaxhighlight>
 
=={{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
or move the subtraction into the body of the FOR loop
<syntaxhighlight lang="ALGOL">
begin
 
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
</syntaxhighlight>
{{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>
 
=={{header|ALGOL W}}==
Line 560 ⟶ 589:
Disp 10-I▶Dec,i
End</syntaxhighlight>
 
=={{header|Bait}}==
<syntaxhighlight lang="bait">
fun main() {
for i := 10; i >= 0; i -= 1 {
println(i)
}
}
</syntaxhighlight>
 
=={{header|BASIC}}==
Line 586 ⟶ 624:
20 PRINT I
30 NEXT</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|FBSL}}===
Line 594 ⟶ 635:
NEXT
 
PAUSE</syntaxhighlight>
</syntaxhighlight>
 
==={{header|FreeBASIC}}===
Line 606 ⟶ 646:
Sleep</syntaxhighlight>
{{out}}
<pre> 10 9 8 7 6 5 4 3 2 1 0</pre>
<pre>
10 9 8 7 6 5 4 3 2 1 0
</pre>
 
==={{header|FutureBasic}}===
Line 620 ⟶ 658:
next
 
HandleEvents</syntaxhighlight>
</syntaxhighlight>
Output:
<pre> 10
10
9
8
Line 634 ⟶ 670:
2
1
0</pre>
</pre>
 
==={{header|Gambas}}===
Line 648 ⟶ 683:
End</syntaxhighlight>
Output:
<pre>10 9 8 7 6 5 4 3 2 1 0</pre>
<pre>
10 9 8 7 6 5 4 3 2 1 0
</pre>
 
==={{header|GW-BASIC}}===
{{works with|BASICA}}
{{works with|PC-BASIC|any}}
<syntaxhighlight lang="gwbasic">10 FOR I% = 10 TO 0 STEP -1
10 FOR I% = 10 TO 0 STEP -1
20 PRINT I%
30 NEXT I%</syntaxhighlight>
</syntaxhighlight>
 
==={{header|IS-BASIC}}===
Line 669 ⟶ 700:
{{works with|Just BASIC}}
{{works with|Run BASIC}}
<syntaxhighlight lang="lb">for i = 10 to 0 step -1
for i = 10 to 0 step -1
print i
next i
Line 680 ⟶ 710:
TextWindow.WriteLine(i)
EndFor</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|NS-HUBASIC}}===
Line 701 ⟶ 734:
print i
next i</syntaxhighlight>
 
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Run BASIC}}===
Line 711 ⟶ 747:
 
==={{header|TI-83 BASIC}}===
<syntaxhighlight lang="ti83b">:For(I,10,0,-1
:For(I,10,0,-1
:Disp I
:End</syntaxhighlight>
:End
</syntaxhighlight>
 
==={{header|TI-89 BASIC}}===
Line 826 ⟶ 860:
<syntaxhighlight lang="cpp">for(int i = 10; i >= 0; --i)
std::cout << i << "\n";</syntaxhighlight>
 
=={{header|C3}}==
<syntaxhighlight lang="c3">for (int i = 10; i >= 0; i--)
{
io::printn(i);
}</syntaxhighlight>
 
=={{header|Ceylon}}==
Line 1,020 ⟶ 1,060:
0</pre>
 
=={{header|dcDart}}==
<syntaxhighlight lang="dart">void main() {
for (var i = 10; i >= 0; --i) {
print(i);
}
}</syntaxhighlight>
 
=={{header|dc}}==
does not use GNU extensions
 
Line 1,541 ⟶ 1,587:
 
=={{header|langur}}==
You can use a for in loop to count downward. You cannot use a for of loop for this.
 
<syntaxhighlight lang="langur">for .i in 10..0 {
writeln .i
Line 1,553 ⟶ 1,597:
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">loop(-from=10, -to=0, -by=-1) => {^ loop_count + ' ' ^}</syntaxhighlight>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
i is number
 
procedure:
for i from 10 to -1 step -1 do
display i lf
repeat</syntaxhighlight>
 
=={{header|Lhogho}}==
Line 1,754 ⟶ 1,807:
NEW I FOR I=10:-1:1 WRITE I WRITE:I'=1 ", "
KILL I QUIT</syntaxhighlight>
 
=={{header|N/t/roff}}==
<syntaxhighlight lang="nroff">
.nr a 11 1
.while (\na > 0) \{\
\n-a
.\}
</syntaxhighlight>
{{out}}
<pre>10 9 8 7 6 5 4 3 2 1 0
</pre>
 
=={{header|Nemerle}}==
Line 1,789 ⟶ 1,853:
1
0</pre>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
for i in 10..0 {print $i}
</syntaxhighlight>
 
=={{header|Oberon-2}}==
Line 2,061 ⟶ 2,130:
end;
end;</syntaxhighlight>
 
=={{header|S-BASIC}}==
<syntaxhighlight lang="BASIC">
var i = integer
for i = 10 to 1 step -1
print i;
next i
 
end
</syntaxhighlight>
{{out}}
<pre>
10 9 8 7 6 5 4 3 2 1
</pre>
 
=={{header|Scala}}==
Line 2,387 ⟶ 2,470:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">for (i in 10..0) System.write("%(i) ")
System.print()</syntaxhighlight>
 
13

edits