# New to Programming: Value of gets for just "Enter"

**URL:** <https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689>\
**Category:** Ruby\
**Created:** [June 7, 2009, 1:50am UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689 "2009-06-07T01:50:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 7, 2009, 1:50am UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/1 "2009-06-07T01:50:50Z")

</div>

Hello,  
I am new to programming in general, and I was having a difficult time  
figuring out the solution to this problem as well as thinking of good  
key words that would help me find the solution online.

My problem is simply that I do not know what the value of a ‘gets’ that  
doesn’t contain anything is. I want this program to end if someone just  
hits enter for the gets response, and I don’t know how to represent that  
in the program itself.

puts ‘Enter as many words as you please, one per line. Press enter to  
quit.’  
array = []  
input = gets.chomp.downcase  
if input != # Not sure what should go here  
while input != # Not sure what should go here  
array.push input.capitalize  
input = gets.chomp.downcase  
end  
else  
end  
puts array.sort

If anyone could help me out with this I would be very grateful. I am  
sure there is a very simple solution, but I have been looking around  
quite a bit, and have been unable to find anything.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 7, 2009, 3:26am UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/2 "2009-06-07T03:26:54Z")

</div>

On Sat, Jun 6, 2009 at 7:50 PM, Matt Garriott[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> puts 'Enter as many words as you please, one per line. Press enter to  
> puts array.sort
> 
> If anyone could help me out with this I would be very grateful. I am  
> sure there is a very simple solution, but I have been looking around  
> quite a bit, and have been unable to find anything.

It will return an empty string

if input != “”

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 8, 2009, 7:59am UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/3 "2009-06-08T07:59:29Z")

</div>

7stud – wrote:

> print "Enter: "  
> input = gets  
> p input
> 
> –output:–  
> Enter:  
> “\n”

Whenever you hit Enter/Return on your keyboard, you are adding a  
“newline” to the input. A newline is signified by the string “\n”.

---

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 8, 2009, 7:47am UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/4 "2009-06-08T07:47:27Z")

</div>

Matt Garriott wrote:

> Hello,  
> I am new to programming in general, and I was having a difficult time  
> figuring out the solution to this problem as well as thinking of good  
> key words that would help me find the solution online.
> 
> My problem is simply that I do not know what the value of a ‘gets’ that  
> doesn’t contain anything is. I want this program to end if someone just  
> hits enter for the gets response, and I don’t know how to represent that  
> in the program itself.

print "Enter: "  
input = gets  
p input

–output:–  
Enter:  
“\n”

---

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 8, 2009, 5:09pm UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/5 "2009-06-08T17:09:06Z")

</div>

On Mon, 08 Jun 2009 14:59:31 +0900, 7stud – wrote:

> Whenever you hit Enter/Return on your keyboard, you are adding a  
> “newline” to the input. A newline is signified by the string “\n”.

And then the chomp function which he calls on the string removes the \n  
from the end, making it an empty string.

---

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 8, 2009, 6:14pm UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/6 "2009-06-08T18:14:43Z")

</div>

Ken B. wrote:

> On Mon, 08 Jun 2009 14:59:31 +0900, 7stud – wrote:
> 
> > Whenever you hit Enter/Return on your keyboard, you are adding a  
> > “newline” to the input. A newline is signified by the string “\n”.
> 
> And then the chomp function which he calls on the string removes the \n  
> from the end, making it an empty string.

Really?

---

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 9, 2009, 4:31am UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/7 "2009-06-09T04:31:01Z")

</div>

7stud – wrote:

> Ken B. wrote:
> 
> > On Mon, 08 Jun 2009 14:59:31 +0900, 7stud – wrote:
> > 
> > > Whenever you hit Enter/Return on your keyboard, you are adding a  
> > > “newline” to the input. A newline is signified by the string “\n”.  
> > > And then the chomp function which he calls on the string removes the \n  
> > > from the end, making it an empty string.
> 
> Really?

if input.chomp.strip != “”

---

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 9, 2009, 8:48pm UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/8 "2009-06-09T20:48:20Z")

</div>

botp wrote:

> On Tue, Jun 9, 2009 at 10:30 AM, Rha7[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > if input.chomp.strip != “”
> 
> irb(main):001:0\> “\n”.strip  
> =\> “”  
> irb(main):002:0\> " \n ".strip  
> =\> “”

rha7.illuminated.chomp

---

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [June 9, 2009, 4:41am UTC](https://www.ruby-forum.com/t/new-to-programming-value-of-gets-for-just-enter/169689/9 "2009-06-09T04:41:32Z")

</div>

On Tue, Jun 9, 2009 at 10:30 AM, Rha7[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if input.chomp.strip != “”

irb(main):001:0\> “\n”.strip  
=\> “”  
irb(main):002:0\> " \n ".strip  
=\> “”
