From: Matthew Kerwin Date: 2013-07-18T07:55:12+09:00 Subject: Re: Iteration anomalu Sascha Abel wrote in post #1115792: > Just try > > for i in [0..a.length] do > print i > end > > and you should have your answer. And to expand, in case it's not entirely clear: * [x..y] constructs an Array with one element, and that element is a Range * Array#[] accepts a Range parameter for i in [0..a.length] i # i == (0..a.length) a[i] # same as: a[0..a.length] end I believe you want to do this: for i in 0..a.length do #<-- no brackets! print a[i], "\n" end However, to be honest, this is one of the only times I've ever seen a "for" loop written in Ruby code. The more typical, paradigmatic approach would be: a.each do |el| print el, "\n" end ... and for the nested iteration: a.each_index do |i| a[i+1..-1].each_with_index do |cell,j| # processing on `cell` or `j`... end end ... or something like that. Also note that you can call .each on a range, e.g.: (0...a.length).each do |i| ... -- Posted via http://www.ruby-forum.com/.