# Strange Ruby Issue in SciTE - Won't Parse First Input

**URL:** <https://www.ruby-forum.com/t/strange-ruby-issue-in-scite-wont-parse-first-input/89139>\
**Category:** Ruby\
**Created:** [March 17, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/strange-ruby-issue-in-scite-wont-parse-first-input/89139 "2007-03-17T19:43:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [March 17, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/strange-ruby-issue-in-scite-wont-parse-first-input/89139/1 "2007-03-17T19:43:55Z")

</div>

NOTE: I posted this in the RForum category accidentally, and it seems  
very dead there so here I am.

Yeah, I know. Very bad topic title, but there is no quick way to  
describe this problem in 2 words:

I am learning Ruby right now, and I am using the wonderful Learning R.  
guide by Satish T… I am currently at the chapter “Random Numbers”  
and I am trying to do the following:

This assignment is from Chris P.'s Book.

1. Write a Deaf Grandma program. Whatever you say to grandma  
(whatever you type in), she should respond with HUH?! SPEAK UP, SONNY!,  
unless you shout it (type in all capitals). If you shout, she can hear  
you (or at least she thinks so) and yells back, NO, NOT SINCE 1938! To  
make your program really believable, have grandma shout a different year  
each time; maybe any year at random between 1930 and 1950. You can’t  
stop talking to grandma until you shout BYE.
2. Extend your Deaf Grandma program: What if grandma doesn’t want you  
to leave? When you shout BYE, she could pretend not to hear you. Change  
your previous program so that you have to shout BYE three times in a  
row. Make sure to test your program: if you shout BYE three times, but  
not in a row, you should still be talking to grandma.

I have done all of that, but I have one problem. I am using SciTE, and  
am using the F5 thing to try out my code. My one problem is that when I  
run the program, the correct text comes on, but I have to press enter  
twice for the while loop to start. Sounds confusing, I know, so here is  
my code:

bye\_response = 0  
years = (1930…1950).to\_a

puts “'Ey sonny! Long time no chat with your old nonna, eh? How ya  
been!?”  
STDOUT.flush

response = gets.chomp  
while bye\_response != 3  
response = gets.chomp  
if bye\_response == 2  
puts “FINE! LEAVE YOUR OLD NONNA!”  
bye\_response += 1  
elsif response == “BYE”  
puts “HUH!? WHAT WAS THAT!?”  
bye\_response += 1  
elsif response == response.upcase  
puts "NO, NOT SINCE " + years[rand(years.max - years.min)].to\_s +  
“!”  
bye\_response = 0  
else  
puts “HUH?! SPEAK UP, SONNY!”  
bye\_response = 0  
end  
STDOUT.flush  
end

Try it out in SciTE and you’ll see what I mean. If you don’t have SciTE  
and still want to see what I mean, I took a screenshot:  
[http://www.michaelboutros.com/uploads/ruby.jpg](http://www.michaelboutros.com/uploads/ruby.jpg). Thanks a lot!

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [March 17, 2007, 7:46pm UTC](https://www.ruby-forum.com/t/strange-ruby-issue-in-scite-wont-parse-first-input/89139/2 "2007-03-17T19:46:42Z")

</div>

Sorry! I didn’t post the updated code:

bye\_response = 0  
years = (1930…1950).to\_a

puts “'Ey sonny! Long time no chat with your old nonna, eh? How ya  
been!?”  
STDOUT.flush

response = gets.chomp

while bye\_response != 3  
response = gets.chomp  
if response == “BYE”  
if bye\_response == 2  
puts “FINE! LEAVE YOUR OLD NONNA!”  
else  
puts “HUH!? WHAT WAS THAT!?”  
end  
bye\_response += 1  
elsif response == response.upcase  
puts "NO, NOT SINCE " + years[rand(years.max - years.min)].to\_s +  
“!”  
bye\_response = 0  
else  
puts “HUH?! SPEAK UP, SONNY!”  
bye\_response = 0  
end  
STDOUT.flush  
end

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [March 17, 2007, 7:55pm UTC](https://www.ruby-forum.com/t/strange-ruby-issue-in-scite-wont-parse-first-input/89139/3 "2007-03-17T19:55:49Z")

</div>

Michael B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I have done all of that, but I have one problem. I am using SciTE, and  
> am using the F5 thing to try out my code. My one problem is that when I  
> run the program, the correct text comes on, but I have to press enter  
> twice for the while loop to start.

No, you have to press enter once for the while loop to start, and  
another time _in_ the while loop:

> bye\_response = 0  
> years = (1930…1950).to\_a
> 
> puts “'Ey sonny! Long time no chat with your old nonna, eh? How ya  
> been!?”  
> STDOUT.flush
> 
> response = gets.chomp

Here you have demanded the first enter.

> while bye\_response != 3  
> response = gets.chomp

And here you have demanded the second one, before even doing anything  
with the previous response.

I suggest that you remove the first of those lines asking for input:  
it does not actually get used anywhere.

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [March 17, 2007, 8:01pm UTC](https://www.ruby-forum.com/t/strange-ruby-issue-in-scite-wont-parse-first-input/89139/4 "2007-03-17T20:01:20Z")

</div>

David K. wrote:

> I suggest that you remove the first of those lines asking for input:  
> it does not actually get used anywhere.

Ah, that makes sense. Thanks a lot for your help David 🙂
