New to ruby

why does my while loop never end?

puts ‘Please enter a number:’
number = gets.chomp.to_i
while number != ‘’
if number > 0
puts ‘You have entered a number greater than 0’
end
puts ‘Please enter a number’
number = gets.chomp.to_i
end
puts ‘Goodbye!’

From: Imraan M. [mailto:[email protected]]

why does my while loop never end?

check your while condition, pls.

puts ‘Please enter a number:’

number = gets.chomp.to_i

number is an integer

while number != ‘’

then you’re comparing it w a string

Hello,

Is there any other source where I could download the gem
activerecord-sybase-adapter.

I have been trying to access http://gems.rubyonrails.org all day, which
hosts these adapters according to
http://weblog.rubyonrails.org/2007/10/1/adapter-gems-available but to no
avail.

http://gems.rubyforge.net didn’t yield anything either.

I am upgrading to rails 2.0 and this is holding me back.

Many Thanks,
Aman



This message is intended only for the personal and confidential use of
the designated recipient(s) named above. If you are not the intended
recipient of this message you are hereby notified that any review,
dissemination, distribution or copying of this message is strictly
prohibited. This communication is for information purposes only and
should not be regarded as an offer to sell or as a solicitation of an
offer to buy any financial product, an official confirmation of any
transaction, or as an official statement of Lehman Brothers. Email
transmission cannot be guaranteed to be secure or error-free.
Therefore, we do not represent that this information is complete or
accurate and it should not be relied upon as such. All information is
subject to change without notice.

Because gets.chomp.to_i will never be an empty string (’’).

‘’.to_i
–> 0

nil.to_i
–> 0

Regards,
Nicolai

Hi Imraan,

On Mon, 10 Dec 2007 04:55:51 -0500
Imraan M. [email protected] wrote:

why does my while loop never end?

puts ‘Please enter a number:’
number = gets.chomp.to_i

casting to an integer

while number != ‘’

this is a string
(while number > 0)

if number > 0
puts ‘You have entered a number greater than 0’
end
puts ‘Please enter a number’
number = gets.chomp.to_i

casting to an integer

end
puts ‘Goodbye!’

cheers,

Thank you all. I understand now! :slight_smile:

Mark W. wrote:

Hi Imraan,

On Mon, 10 Dec 2007 04:55:51 -0500
Imraan M. [email protected] wrote:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs