# Form Control

**URL:** <https://www.ruby-forum.com/t/form-control/143319>\
**Category:** Ruby\
**Created:** [July 17, 2008, 10:20am UTC](https://www.ruby-forum.com/t/form-control/143319 "2008-07-17T10:20:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dev1](https://www.ruby-forum.com/u/dev1)\
**Post date:** [July 17, 2008, 10:20am UTC](https://www.ruby-forum.com/t/form-control/143319/1 "2008-07-17T10:20:05Z")

</div>

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 P.'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

---

<div class="post-metadata">

**Author:** ![dev1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dev1](https://www.ruby-forum.com/u/dev1)\
**Post date:** [July 17, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/form-control/143319/2 "2008-07-17T17:04:25Z")

</div>

Thanks James, I appreciate your assistance and making me feel most  
welcomed 🙂

Cheers,  
devy

---

<div class="post-metadata">

**Author:** ![dev1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dev1](https://www.ruby-forum.com/u/dev1)\
**Post date:** [July 17, 2008, 3:20pm UTC](https://www.ruby-forum.com/t/form-control/143319/3 "2008-07-17T15:20:08Z")

</div>

On Jul 17, 2008, at 3:15 AM, Devious Forlan wrote:

> 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.

Great. Welcome to Ruby!

> Can someone please take a look at my code, it’s s simple loop as per  
> Chris P.'s Learn to Program book.

Sure, I can take a look.

> ## 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

Looking good to me.

> What’s the the most correct context because I’m still wrapping my head  
> around this.

As you said, the two are equivalent. There’s no right or wrong way to  
represent it. It’s probably best to use whichever one you feel makes  
the code the most clear. However, I don’t think there’s much  
difference for this particular case.

Again, nice job and welcome.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![dev1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dev1](https://www.ruby-forum.com/u/dev1)\
**Post date:** [July 18, 2008, 5:22pm UTC](https://www.ruby-forum.com/t/form-control/143319/4 "2008-07-18T17:22:30Z")

</div>

Thanks Marc,

Like you my brain can only comprehend simple things 🙂

I’m really hoping I can finish Chris P.'s Learn to Program tutorial  
and take it from there.

Cheers

Marc H. wrote:

> BTW instead of
> 
> bottles = bottles - 1
> 
> you can also do
> 
> bottles -= 1
> 
> Granted, it is not a huge change.
> 
> About
> 
> if bottles == 0
> 
> vs
> 
> if bottles != 1
> 
> I’d prefer the first. For some reason my brain likes simple things  
> like == more than != which becomes especially complicated for my  
> brain to process when it is  
> unless bottles != 1 and bottles \>= 5
> 
> 🙂

---

<div class="post-metadata">

**Author:** ![dev1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dev1](https://www.ruby-forum.com/u/dev1)\
**Post date:** [July 17, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/form-control/143319/5 "2008-07-17T18:54:21Z")

</div>

BTW instead of

bottles = bottles - 1

you can also do

bottles -= 1

Granted, it is not a huge change.

About

if bottles == 0

vs

if bottles != 1

I’d prefer the first. For some reason my brain likes simple things  
like == more than != which becomes especially complicated for my  
brain to process when it is  
unless bottles != 1 and bottles \>= 5

🙂

---

<div class="post-metadata">

**Author:** ![dev1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dev1](https://www.ruby-forum.com/u/dev1)\
**Post date:** [July 18, 2008, 7:23pm UTC](https://www.ruby-forum.com/t/form-control/143319/6 "2008-07-18T19:23:07Z")

</div>

Marc H. wrote:

> For some reason my brain likes simple things

Everyone’s brain likes simple things. Unfortunately one of the  
side-effects of education is to make people believe that complex things  
are somehow better. In kindergarten we learn that “Simple Simon” means  
stupid Simon, and the process carries on right up to higher degree  
level. Hence all those mathematical papers full of incomprehensible  
formulae, most of which say nothing of interest.

I’ve come to the conclusion that 90% of people are “complicators”: give  
them a problem and they’ll add bells and whistles to it and make it more  
complex than it started out.

I like to think I’m in the other 10%, the “simplifiers”. We strip the  
problem down to its bare necessities, see the underlying simplicity, and  
get things done. 🙂

Dave
