D
Devious Forlan
Hi guys,
I've started learning Ruby and I'm really, really enjoying it. I have no
prior experience with any programming language, and I've been reading,
listening and watching as much Ruby related material I can.
Can someone please take a look at my code, it's s simple loop as per
Chris Pine's Learn to Program book.
This is what I've come up with to print the 99 bottles poem
-----
01| bottles = 99
02|
03| while bottles != 0
04| puts bottles.to_s + ' of beer on the wall! ' + bottles.to_s + ' of
beer!'
05| puts 'Take one down, and pass it around, now there is..'
06|
07| bottles = bottles - 1
08|
09| if bottles == 0
10| puts bottles.to_s + ' of beer on the wall'
11| puts bottles.to_s + ' bottles of beer!'
12| end
13|
14| end
-----
Can someone tell me if I'm on the right track?
For example.
09| if bottles == 0
I've seen people use the following instead
Ex| if bottles != 1
What's the the most correct context because I'm still wrapping my head
around this.
If != means "Are these different"
Example if I change the code from == to != it will do the same thing
09| if bottles != 1
10| puts bottles.to_s + ' of beer on the wall'
11| puts bottles.to_s + ' bottles of beer!'
12| end
So, will it count from 99, 98, 97, etc.. when it reaches number 1 the !=
method will return a 'false' and therefor output whatever is in the if
statement, is this correct?
but if i read this in my head:
I apologize for not being smart.
Thanks in advance,
devy
I've started learning Ruby and I'm really, really enjoying it. I have no
prior experience with any programming language, and I've been reading,
listening and watching as much Ruby related material I can.
Can someone please take a look at my code, it's s simple loop as per
Chris Pine's Learn to Program book.
This is what I've come up with to print the 99 bottles poem
-----
01| bottles = 99
02|
03| while bottles != 0
04| puts bottles.to_s + ' of beer on the wall! ' + bottles.to_s + ' of
beer!'
05| puts 'Take one down, and pass it around, now there is..'
06|
07| bottles = bottles - 1
08|
09| if bottles == 0
10| puts bottles.to_s + ' of beer on the wall'
11| puts bottles.to_s + ' bottles of beer!'
12| end
13|
14| end
-----
Can someone tell me if I'm on the right track?
For example.
09| if bottles == 0
I've seen people use the following instead
Ex| if bottles != 1
What's the the most correct context because I'm still wrapping my head
around this.
If != means "Are these different"
Example if I change the code from == to != it will do the same thing
09| if bottles != 1
10| puts bottles.to_s + ' of beer on the wall'
11| puts bottles.to_s + ' bottles of beer!'
12| end
So, will it count from 99, 98, 97, etc.. when it reaches number 1 the !=
method will return a 'false' and therefor output whatever is in the if
statement, is this correct?
but if i read this in my head:
I apologize for not being smart.
Thanks in advance,
devy