From: Marnen Laibow-Koser Date: 2009-12-01T14:56:23+09:00 Subject: Re: have a problem with the loops and variable Michael Linfield wrote: > >> My last code : >> ----------------- >> q = 1 >> w = 2 >> while q < w >> s[q] = 1 >> puts s[q] >> q += 1 >> end >> ----------------- >> >> Why does not work ? > > You should be declaring s as an array: s[] > >>> s = [] > => [] >>> q = 1 > => 1 >>> w = 2 > => 2 >>> while q < w > .. s[q] = 1 > .. puts s[q] > .. q += 1 > .. end > 1 > => nil >>> Note that it would be far more idiomatic to use s.each. Never use += to step through subscripts in Ruby. Best, --  Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.