Jump to content

Loops/Nested: Difference between revisions

Updated to work with Nim 1.4. Changed the way to initialize the array. Done other syntactical changes.
(Added 11l)
(Updated to work with Nim 1.4. Changed the way to initialize the array. Done other syntactical changes.)
Line 2,518:
 
=={{header|Nim}}==
<lang nim>import mathrandom, strutils
 
const arrSizeArrSize = 10
 
var a: array[0..arrSize-1ArrSize, array[0..arrSize-1ArrSize, int]]
var s: string = ""
 
randomize() # differentDifferent results each time this runs.
 
# Initialize using loops on items rather than indexes.
for i in 0 .. arrSize-1:
for jrow in countup(0,arrSize-1)a.mitems:
for item in row.mitems:
a[i][j] = random(20)+1
item = rand(1..20)
 
block outer:
# Loop using indexes.
for i in countup(0,arrSize-1):
for ji in 0 .. arrSize-1<ArrSize:
for j in if a[i][j] 0..< 10ArrSize:
if a[i][j] < 10: s.add("' "')
addf(s, "$#", $a[i][j])
if a[i][j] == 20: break outer
s.add(", break outer")
s.add(", "'\n')
 
s.add("\n")
echo( s)</lang>
 
{{out}}
<pre> 9, 16, 3, 18, 4, 17, 2, 16, 7, 6,
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.