Create a two-dimensional array at runtime: Difference between revisions

Content added Content deleted
(Updated code to work with version 1.4 of Nim.)
(Added comments and completed the task.)
Line 1,497: Line 1,497:
=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import strutils, rdstdin
<lang nim>import strutils, rdstdin

let
var
w = readLineFromStdin("Width: ").parseInt()
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
s = newSeq[seq[int]](h)


# Create the rows.
var s = newSeq[seq[int]](h)
# Create the columns.
for i in 0 ..< h:
for i in 0 ..< h:
s[i].newSeq(w)</lang>
s[i].newSeq(w)

# Store a value in an element.
s[0][0] = 5

# Retrieve and print it.
echo s[0][0]

# The allocated memory is freed by the garbage collector.</lang>


=={{header|Objeck}}==
=={{header|Objeck}}==