Loops/Nested: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added Pike implementation)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 164:
+3 +13 +6 +8 +6 +10 +9 +15 +20
</pre>
 
 
=={{header|ALGOL 68}}==
Line 430 ⟶ 429:
bx lr
</lang>
 
 
=={{header|AutoHotkey}}==
Line 613 ⟶ 611:
Done:
printf("\n");
return 0;
}</lang>
 
=={{header|C++}}==
Lambda call:
{{works with|C++11}}
<lang cpp>#include<cstdlib>
#include<ctime>
#include<iostream>
 
using namespace std;
int main()
{
int arr[10][10];
srand(time(NULL));
for(auto& row: arr)
for(auto& col: row)
col = rand() % 20 + 1;
 
([&](){
for(auto& row : arr)
for(auto& col: row)
{
cout << col << endl;
if(col == 20)return;
}
})();
return 0;
}</lang>
Goto statement:
{{works with|C++11}}
<lang cpp>#include<cstdlib>
#include<ctime>
#include<iostream>
 
using namespace std;
int main()
{
int arr[10][10];
srand(time(NULL));
for(auto& row: arr)
for(auto& col: row)
col = rand() % 20 + 1;
 
for(auto& row : arr) {
for(auto& col: row) {
cout << ' ' << col;
if (col == 20) goto out;
}
cout << endl;
}
out:
 
return 0;
}</lang>
Line 724 ⟶ 669:
Console.WriteLine();
}
}</lang>
 
=={{header|C++}}==
Lambda call:
{{works with|C++11}}
<lang cpp>#include<cstdlib>
#include<ctime>
#include<iostream>
 
using namespace std;
int main()
{
int arr[10][10];
srand(time(NULL));
for(auto& row: arr)
for(auto& col: row)
col = rand() % 20 + 1;
 
([&](){
for(auto& row : arr)
for(auto& col: row)
{
cout << col << endl;
if(col == 20)return;
}
})();
return 0;
}</lang>
Goto statement:
{{works with|C++11}}
<lang cpp>#include<cstdlib>
#include<ctime>
#include<iostream>
 
using namespace std;
int main()
{
int arr[10][10];
srand(time(NULL));
for(auto& row: arr)
for(auto& col: row)
col = rand() % 20 + 1;
 
for(auto& row : arr) {
for(auto& col: row) {
cout << ' ' << col;
if (col == 20) goto out;
}
cout << endl;
}
out:
 
return 0;
}</lang>
 
Line 860 ⟶ 858:
writeln();
}</lang>
 
=={{header|Delphi}}/{{header|Pascal}}==
<lang delphi>var
matrix: array[1..10,1..10] of Integer;
row, col: Integer;
broken: Boolean;
begin
// Launch random number generator
randomize;
// Filling matrix with random numbers
for row := 1 to 10 do
for col := 1 to 10 do
matrix[row, col] := Succ(Random(20));
// Displaying values one by one, until at the end or reached number 20
Broken := False;
for row := 1 to 10 do
begin
for col := 1 to 10 do
begin
ShowMessage(IntToStr(matrix[row, col]));
if matrix[row, col] = 20 then
begin
Broken := True;
break;
end;
end;
if Broken then break;
end;
end;</lang>
 
=={{header|dc}}==
Line 962 ⟶ 931:
lb >L [Enter outer loop.]sz</lang>
In this program, ''li lj + 3 + Q'' breaks both the inner loop and the outer loop. We must count how many levels of string execution to break. Our loops use tail recursion, so each iteration is a level of string execution. We have i + 1 calls to outer loop L, and j + 1 calls to inner loop I, and 1 call to condition D; so we break i + j + 3 levels with ''li lj + 3 + Q''.
 
=={{header|Delphi}}/{{header|Pascal}}==
<lang delphi>var
matrix: array[1..10,1..10] of Integer;
row, col: Integer;
broken: Boolean;
begin
// Launch random number generator
randomize;
// Filling matrix with random numbers
for row := 1 to 10 do
for col := 1 to 10 do
matrix[row, col] := Succ(Random(20));
// Displaying values one by one, until at the end or reached number 20
Broken := False;
for row := 1 to 10 do
begin
for col := 1 to 10 do
begin
ShowMessage(IntToStr(matrix[row, col]));
if matrix[row, col] = 20 then
begin
Broken := True;
break;
end;
end;
if Broken then break;
end;
end;</lang>
 
=={{header|Dyalect}}==
Line 2,106 ⟶ 2,104:
Checkit
</lang>
 
 
=={{header|Maple}}==
Line 2,605 ⟶ 2,602:
}
print "\n";</lang>
 
=={{header|Perl 6}}==
{{works with|rakudo|2015-09-18}}
<lang perl6>my @a = [ (1..20).roll(10) ] xx *;
 
LINE: for @a -> @line {
for @line -> $elem {
print " $elem";
last LINE if $elem == 20;
}
print "\n";
}
print "\n";</lang>
{{out}}
<pre> 15 6 14 13 14 7 9 16 8 18
7 6 18 11 19 13 12 5 18 8
17 17 9 5 4 8 17 8 3 11
9 20</pre>
 
=={{header|Phix}}==
Line 2,880 ⟶ 2,859:
 
(scan matrix)</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|rakudo|2015-09-18}}
<lang perl6>my @a = [ (1..20).roll(10) ] xx *;
 
LINE: for @a -> @line {
for @line -> $elem {
print " $elem";
last LINE if $elem == 20;
}
print "\n";
}
print "\n";</lang>
{{out}}
<pre> 15 6 14 13 14 7 9 16 8 18
7 6 18 11 19 13 12 5 18 8
17 17 9 5 4 8 17 8 3 11
9 20</pre>
 
=={{header|REBOL}}==
Line 3,118 ⟶ 3,116:
[end]
print "At row:";row;" col:";col</lang>
 
 
=={{header|Rust}}==
Line 3,434 ⟶ 3,431:
biarr whileTrue: [ :v | v ~= 20 ]
do: [ :v | v displayNl ]</lang>
 
=={{header|SPL}}==
<lang spl>'fill array
10,327

edits