Iterating over two dimension array and knowing current position
Posted
by Nuno Furtado
on Stack Overflow
See other posts from Stack Overflow
or by Nuno Furtado
Published on 2010-03-23T13:26:26Z
Indexed on
2010/03/23
13:33 UTC
Read the original article
Hit count: 429
I am trying to iterate a multidimension array created with the following line
To iterate i'm using the following code
visiblematrix= Array.new (10) {Array.new(10){0}}
But this doesn't allow me to know the current x,y position while iterating. how can i find it out without resorting to temporary variables
visiblematrix.each do |x|
x.each do |y|
puts y
end
end
© Stack Overflow or respective owner