Loops/For: Difference between revisions

1,895 bytes added ,  1 month ago
Zig sorted alphabetically before zkn
m (J: simplify, and update to the prettier syntax of J release 9)
(Zig sorted alphabetically before zkn)
(17 intermediate revisions by 15 users not shown)
Line 590:
The key operator here is 'iter' which gives the current iteration of the loop body it
resides in. When used with the 'times' operator, it generates a countdown.
 
=={{header|Bait}}==
<syntaxhighlight lang="bait">
const ROWS := 5
 
fun main() {
for i := 1; i <= ROWS; i += 1 {
for j := 1; j <= i; j += 1 {
print('*')
}
println('')
}
}
</syntaxhighlight>
 
 
=={{header|bash}}==
Line 644 ⟶ 659:
NEXT
</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 for i = 1 to 5
20 for j = 1 to i
30 print "*";
40 next j
50 print
60 next i</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 753 ⟶ 777:
next
print
next</syntaxhighlight>
next
</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Microsoft Small Basic}}===
Line 777 ⟶ 802:
CloseConsole()
EndIf</syntaxhighlight>
 
==={{header|QBasic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
Also
The [[#BASIC256|BASIC256]] solution works without any changes.
 
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">FOR i = 1 TO 5
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT "*";
NEXT j
PRINT
NEXT i</syntaxhighlight>
</syntaxhighlight>
 
==={{header|smart BASIC}}===
Line 797 ⟶ 828:
print
next n</syntaxhighlight>
 
 
==={{header|True BASIC}}===
<syntaxhighlight lang="basic">FOR i = 1 TO 5
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT "*";
Line 807 ⟶ 836:
PRINT
NEXT i
END</syntaxhighlight>
END
</syntaxhighlight>
 
 
==={{header|Visual Basic}}===
Line 840 ⟶ 867:
 
==={{header|ZX Spectrum Basic}}===
 
On the ZX Spectrum, we need line numbers:
 
<syntaxhighlight lang="basic">10 FOR i = 1 TO 5
10 FOR i = 1 TO 5
20 FOR j = 1 TO i
30 PRINT "*";
40 NEXT j
50 PRINT
60 NEXT i</syntaxhighlight>
</syntaxhighlight>
 
=={{header|Batch File}}==
 
<syntaxhighlight lang="text">@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
Line 888 ⟶ 911:
| :-1<
^+1,+5+5<</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
 
The following 22-byte BLC program is generated from https://github.com/tromp/AIT/blob/master/rosetta/forloops.lam :
 
<pre>18 18 11 50 73 9c e7 40 b3 df cb df 38 1c bd a3 88 05 bb 00 2a 0a</pre>
 
=={{header|blz}}==
Line 959 ⟶ 988:
 
std::cout.put('\n');
}</syntaxhighlight>
 
=={{header|C3}}==
<syntaxhighlight lang="c3">
for (int i = 0; i < 5; i++)
{
for (int j = 1; j <= i; j++) io::print("*");
io::printn("*");
}</syntaxhighlight>
 
Line 1,480 ⟶ 1,517:
 
=={{header|Elena}}==
ELENA 46.x :
<syntaxhighlight lang="elena">import extensions;
public program()
{
for(int i := 0,; i < 5,; i += 1)
{
for(int j := 0,; j <= i,; j += 1)
{ console.write:("*") };
console.writeLine()
Line 1,532 ⟶ 1,569:
output logged in buffer *Messages*:
 
<pre>
*
**
***
****
*****
</pre>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
for int i = 0; i < 5; ++i
for int j = 0; j <= i; ++j do write("*") end
writeLine()
end
</syntaxhighlight>
{{out}}
<pre>
*
Line 2,020 ⟶ 2,073:
end.
EMPTY
}}0
</syntaxhighlight>
 
Line 2,247 ⟶ 2,300:
Or, with one for loop...
<syntaxhighlight lang="langur">for .i of 5 {
writeln "*" x* .i
}</syntaxhighlight>
 
Line 2,294 ⟶ 2,347:
****
*****</pre>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
i is number
j is number
 
procedure:
for i from 1 to 6 step 1 do
for j from 0 to i step 1 do
display "*"
repeat
display lf
repeat
</syntaxhighlight>
{{out}}
<pre>
*
**
***
****
*****
</pre>
 
=={{header|LIL}}==
Line 2,709 ⟶ 2,784:
50 PRINT
60 NEXT</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
for i in 1..5 {
for j in 1..$i {
print -n "*"
}
print ""
}
</syntaxhighlight>
 
=={{header|Oberon-2}}==
Line 3,392 ⟶ 3,477:
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7python">for I range 1 to 5 do
$ include "seed7_05.s7i";
for J range 1 to I do
 
write("*");
const proc: main is func
end for;
local
writeln;
var integer: I is 1;
end for;</syntaxhighlight>
var integer: J is 1;
 
begin
for I range 1 to 5 do
for J range 1 to I do
write("*");
end for;
writeln;
end for;
end func;
</syntaxhighlight>
{{out}}
<pre>
*
**
***
****
*****
</pre>
 
=={{header|SETL}}==
Line 3,768 ⟶ 3,872:
end</syntaxhighlight>
 
==={{header|Korn Shellksh}}===
{{works with|Korn Shell 93ksh93}}
<syntaxhighlight lang="bashksh">for ((x = 1; x <= 5; x=x += 1)); do
do
for ((y=1; y<=x; y=y+1)); do
for ((y = 0; y < x; y += 1))
echo -n '*'
do
done
print -n '*'
echo ""
done
done </syntaxhighlight>
print
done</syntaxhighlight>
 
=={{header|UnixPipes}}==
Line 3,891 ⟶ 3,997:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">for (i in 1..5) {
for (j in 1..i) System.write("*")
System.print()
Line 4,030 ⟶ 4,136:
pop bc
ret ; return to BASIC interpreter</syntaxhighlight>
 
=={{header|Zig}}==
<syntaxhighlight lang="zig">
const std = @import("std");
 
pub fn main() !void {
const stdout_wr = std.io.getStdOut().writer();
for (1..6) |n| {
for (0..n) |_| {
try stdout_wr.writeAll("*");
}
try stdout_wr.writeAll("\n");
}
}
</syntaxhighlight>
{{out}}
<pre>
*
**
***
****
*****
</pre>
 
=={{header|zkl}}==
Line 4,044 ⟶ 4,173:
*****
</pre>
 
=={{header|Zig}}==
<syntaxhighlight lang="zig">const std = @import("std");
 
pub fn main() !void {
const stdout_wr = std.io.getStdOut().writer();
var i: u8 = 1;
while (i < 5) : (i += 1) {
var j: u8 = 1;
while (j <= i) : (j += 1)
try stdout_wr.writeAll("*");
try stdout_wr.writeAll("\n");
}
}</syntaxhighlight>
22

edits