Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
21
Task/Loops-Nested/Ada/loops-nested.adb
Normal file
21
Task/Loops-Nested/Ada/loops-nested.adb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Numerics.Discrete_Random;
|
||||
|
||||
procedure Test_Loop_Nested is
|
||||
type Value_Type is range 1..20;
|
||||
package Random_Values is new Ada.Numerics.Discrete_Random (Value_Type);
|
||||
use Random_Values;
|
||||
Dice : Generator;
|
||||
A : array (1..10, 1..10) of Value_Type :=
|
||||
(others => (others => Random (Dice)));
|
||||
begin
|
||||
|
||||
Outer :
|
||||
for I in A'Range (1) loop
|
||||
for J in A'Range (2) loop
|
||||
Put (Value_Type'Image (A (I, J)));
|
||||
exit Outer when A (I, J) = 20;
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop Outer;
|
||||
end Test_Loop_Nested;
|
||||
45
Task/Loops-Nested/COBOL/loops-nested.cob
Normal file
45
Task/Loops-Nested/COBOL/loops-nested.cob
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. Nested-Loop.
|
||||
|
||||
DATA DIVISION.
|
||||
LOCAL-STORAGE SECTION.
|
||||
78 Table-Size VALUE 10.
|
||||
01 Table-Area.
|
||||
03 Table-Row OCCURS Table-Size TIMES
|
||||
INDEXED BY Row-Index.
|
||||
05 Table-Element PIC 99 OCCURS Table-Size TIMES
|
||||
INDEXED BY Col-Index.
|
||||
|
||||
01 Current-Time PIC 9(8).
|
||||
PROCEDURE DIVISION.
|
||||
* *> Seed RANDOM.
|
||||
ACCEPT Current-Time FROM TIME
|
||||
MOVE FUNCTION RANDOM(Current-Time) TO Current-Time
|
||||
|
||||
* *> Put random numbers in the table.
|
||||
* *> The AFTER clause is equivalent to a nested PERFORM VARYING
|
||||
* *> statement.
|
||||
PERFORM VARYING Row-Index FROM 1 BY 1
|
||||
UNTIL Table-Size < Row-Index
|
||||
AFTER Col-Index FROM 1 BY 1
|
||||
UNTIL Table-Size < Col-Index
|
||||
COMPUTE Table-Element (Row-Index, Col-Index) =
|
||||
FUNCTION MOD((FUNCTION RANDOM * 1000), 20) + 1
|
||||
END-PERFORM
|
||||
|
||||
* *> Search through table for 20.
|
||||
* *> Using proper nested loops.
|
||||
PERFORM VARYING Row-Index FROM 1 BY 1
|
||||
UNTIL Table-Size < Row-Index
|
||||
PERFORM VARYING Col-Index FROM 1 BY 1
|
||||
UNTIL Table-Size < Col-Index
|
||||
IF Table-Element (Row-Index, Col-Index) = 20
|
||||
EXIT PERFORM
|
||||
ELSE
|
||||
DISPLAY Table-Element (Row-Index, Col-Index)
|
||||
END-IF
|
||||
END-PERFORM
|
||||
END-PERFORM
|
||||
|
||||
GOBACK
|
||||
.
|
||||
16
Task/Loops-Nested/Chapel/loops-nested.chpl
Normal file
16
Task/Loops-Nested/Chapel/loops-nested.chpl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use Random;
|
||||
|
||||
var nums:[1..10, 1..10] int;
|
||||
var rnd = new RandomStream();
|
||||
|
||||
[ n in nums ] n = floor(rnd.getNext() * 21):int;
|
||||
delete rnd;
|
||||
|
||||
// this shows a clumsy explicit way of iterating, to actually create nested loops:
|
||||
label outer for i in nums.domain.dim(1) {
|
||||
for j in nums.domain.dim(2) {
|
||||
write(" ", nums(i,j));
|
||||
if nums(i,j) == 20 then break outer;
|
||||
}
|
||||
writeln();
|
||||
}
|
||||
18
Task/Loops-Nested/Euphoria/loops-nested.eu
Normal file
18
Task/Loops-Nested/Euphoria/loops-nested.eu
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
sequence a
|
||||
a = rand(repeat(repeat(20, 10), 10))
|
||||
|
||||
integer wantExit
|
||||
wantExit = 0
|
||||
|
||||
for i = 1 to 10 do
|
||||
for j = 1 to 10 do
|
||||
printf(1, "%g ", {a[i][j]})
|
||||
if a[i][j] = 20 then
|
||||
wantExit = 1
|
||||
exit
|
||||
end if
|
||||
end for
|
||||
if wantExit then
|
||||
exit
|
||||
end if
|
||||
end for
|
||||
9
Task/Loops-Nested/Jactl/loops-nested.jactl
Normal file
9
Task/Loops-Nested/Jactl/loops-nested.jactl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
int[][] nums = 10.map{ 10.map{ random(20) + 1 } }
|
||||
OUTER:
|
||||
for (i = 0; i < nums.size(); i++) {
|
||||
for (j = 0; j < nums[i].size(); j++) {
|
||||
break OUTER if nums[i][j] == 20
|
||||
print sprintf("%2d ", nums[i][j])
|
||||
}
|
||||
println
|
||||
}
|
||||
20
Task/Loops-Nested/ReScript/loops-nested.res
Normal file
20
Task/Loops-Nested/ReScript/loops-nested.res
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
let m = []
|
||||
|
||||
for _ in 0 to 9 {
|
||||
let n = []
|
||||
for _ in 0 to 9 {
|
||||
let _ = Js.Array2.push(n, 1 + Js.Math.random_int(0, 20))
|
||||
}
|
||||
let _ = Js.Array2.push(m, n)
|
||||
}
|
||||
|
||||
try {
|
||||
for i in 0 to 9 {
|
||||
for j in 0 to 9 {
|
||||
Js.log(m[i][j])
|
||||
if m[i][j] == 20 { raise(Exit) }
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
| Exit => Js.log("stop")
|
||||
}
|
||||
38
Task/Loops-Nested/Rebol/loops-nested.rebol
Normal file
38
Task/Loops-Nested/Rebol/loops-nested.rebol
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
REBOL [
|
||||
Title: "Loop/Nested"
|
||||
URL: http://rosettacode.org/wiki/Loop/Nested
|
||||
]
|
||||
|
||||
; Number formatting.
|
||||
zeropad: func [pad n][
|
||||
n: to-string n insert/dup n "0" (pad - length? n) n]
|
||||
|
||||
; Initialize random number generator from current time.
|
||||
random/seed now
|
||||
|
||||
; Create array and fill with random numbers, range 1..20.
|
||||
soup: array [10 10]
|
||||
foreach row soup [forall row [row/1: random 20]]
|
||||
|
||||
print "Loop break using state variable:"
|
||||
done: no
|
||||
for y 1 10 1 [
|
||||
for x 1 10 1 [
|
||||
prin rejoin [zeropad 2 soup/:x/:y " "]
|
||||
if 20 = soup/:x/:y [done: yes break]
|
||||
]
|
||||
prin crlf
|
||||
if done [break]
|
||||
]
|
||||
|
||||
print [crlf "Loop break with catch/throw:"]
|
||||
catch [
|
||||
for y 1 10 1 [
|
||||
for x 1 10 1 [
|
||||
prin rejoin [zeropad 2 soup/:x/:y " "]
|
||||
if 20 = soup/:x/:y [throw 'done]
|
||||
]
|
||||
prin crlf
|
||||
]
|
||||
]
|
||||
prin crlf
|
||||
Loading…
Add table
Add a link
Reference in a new issue