# Newbie question

**URL:** <https://www.ruby-forum.com/t/newbie-question/96041>\
**Category:** Ruby\
**Created:** [June 23, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/newbie-question/96041 "2006-06-23T18:01:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 23, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/newbie-question/96041/1 "2006-06-23T18:01:23Z")

</div>

Sorry because this is probably lame but I’ve been trying to think this  
one through for a few hours and after a few iterations can’t figure  
out the answer. It’s an exercise in the book “Learn to Program”  
(Pragmatic)

Anyway, the problem is I want the program to loop and exit on the input  
‘BYE’  
What’s I’ve come up with is:

$stdout.sync = true (due to weird windows buffer stuff)

input = ‘’

while input != ‘BYE’  
input = gets.chomp

if input == input.upcase  
puts ‘NO, NOT SINCE 1938!’  
elsif input == input.downcase  
puts ‘HUH?! SPEAK UP, SONNY!’

end  
end

What happens is it does exit on BYE but issues the elsif before  
ending. I’ve tried doing a  
if input ==input.upcase !BYE , but was thrown an error. I know UNTIL  
exists but it hasn’t been introduced in the book yet so want to work  
with what I have.

tia  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 23, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/newbie-question/96041/2 "2006-06-23T18:11:17Z")

</div>

> What happens is it does exit on BYE but issues the elsif before  
> ending.

You could initialise input before you go into the while loop, and then  
update it at the end of each iteration:

input = gets.chomp  
while input != ‘BYE’  
if input == input.upcase  
puts ‘NO, NOT SINCE 1938!’  
elsif input == input.downcase  
puts ‘HUH?! SPEAK UP, SONNY!’  
end  
input = gets.chomp  
end

See?

James

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 23, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/newbie-question/96041/3 "2006-06-23T18:27:05Z")

</div>

Yes, thank you James. Works as expected. In some of the examples in  
the book “input” is initialized with a string. i.e.

request = ’ Compared to Go, Chess is like Tic-Tac-Toe.’  
while request != ’ stop’  
puts ’ What would you like to ask C to do?’  
request = gets.chomp

Which is what threw me.

Stuart
