I have been writing codes to perform loop in Column wise iteration and it makes me confuse all the time and I can't distinguish between Column and Row Wise Iteration.
I've written these code below to perform Column Wise Iteration but I'm not sure that it is performing in the right way. Also help me to understand with more examples of Row/Column Iteration
r = {}
for x = 1, 5 do
table.insert(r, {})
end
for x = 1, 5 do
for y = 1, 5 do
table.insert(r[y], y)
-- table.insert(r[x], 'A')
end
end
for x = 1, 5 do
for y = 1, 5 do
io.write(r[x][y], ' : ')
-- io.write(r[y][x], ' :: ')
end
print()
end
OUTPUT:
1 : 1 : 1 : 1 : 1 :
2 : 2 : 2 : 2 : 2 :
3 : 3 : 3 : 3 : 3 :
4 : 4 : 4 : 4 : 4 :
5 : 5 : 5 : 5 : 5 :
This one below is for Row Wise Iteration. I think!
L = {}
for i = 1, 5 do
table.insert(L, {})
for j = 1, 5 do
L[i][j] = " # "
end
end
for i = 1, 5 do
for j = 1, 5 do
io.write(L[i][j])
end
print()
end
OUTPUT:
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #