I have studied C++, Java and I am learning Ruby now.
but It's hard to adapt to iteration in ruby for me yet.
n = 4
arys = Array.new(3, Array.new(n+1, 0))
for i in 1..2
for j in 1..n
arys[i][j] = (i-1)*n+j
end
end
p arys
output of above code is as below
[[0, 5, 6, 7, 8], [0, 5, 6, 7, 8], [0, 5, 6, 7, 8]]
I thought it is like code as below in C
for(int i = 1; i<=2; i++)
for(int j = 1; j<=n; j++)
arys[i][j] = (i-1)*n+j
therefore, I expected the output will be like
[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 5, 6, 7, 8]]
what make the difference between above two codes?