Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: help learning arrays _Thanks
Peter Szinek
11/13/2006 7:22:00 AM
jamison edmonds wrote:
> list = []
OK. So the variable 'list' points to an empty array. So far so good.
> while list != ''
Now you are saying to do something until an array ('list') will be
unequal with an empty string. This will never happen IMHO - usually you
want to compare arrays to arrays and strings to strings (OK, this will
change later, but for now consider it to be so)
> list = gets.chomp
This line changes the whole story. 'list' does not reference an array
any more, but a string, whose value is - after this line is executed -
the string the user types in.
If we now revisit the loop condition
while list != ''
it makes more sense now, since 'list' is a string already, and the loop
will exit if it is empty.
However, there are two problems: the reference to your original empty
array is lost, and anyway, you are not putting anything in there.
How about this:
====================================
list = []
while (input = gets.chomp) != '' do
list << input
end
puts list
====================================
HTH,
Peter
__
http://www.rubyra...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: help learning arrays _Thanks
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password