Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Loops-Nested/Nim/loops-nested.nim
Normal file
25
Task/Loops-Nested/Nim/loops-nested.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import random, strutils
|
||||
|
||||
const ArrSize = 10
|
||||
|
||||
var a: array[ArrSize, array[ArrSize, int]]
|
||||
var s = ""
|
||||
|
||||
randomize() # Different results each time this runs.
|
||||
|
||||
# Initialize using loops on items rather than indexes.
|
||||
for row in a.mitems:
|
||||
for item in row.mitems:
|
||||
item = rand(1..20)
|
||||
|
||||
block outer:
|
||||
# Loop using indexes.
|
||||
for i in 0..<ArrSize:
|
||||
for j in 0..<ArrSize:
|
||||
if a[i][j] < 10: s.add(' ')
|
||||
addf(s, "$#", $a[i][j])
|
||||
if a[i][j] == 20: break outer
|
||||
s.add(", ")
|
||||
s.add('\n')
|
||||
|
||||
echo s
|
||||
Loading…
Add table
Add a link
Reference in a new issue