Hi gang,
Okay, this is referring to the ‘Learn to Program’ thread a little bit.
I think I need to know ‘how’ Ruby looks at a script and how it does
it…at
least I think that’s what I want to know.
In other words, take a simple script like the one below (I know this
one
‘stops’ after ‘shouting’ an answer, heh):
puts ‘(Say Hi to grandma)’
say = gets.chomp
while say != say.upcase
puts ‘HUH!? SPEAK UP! WHAT’RE YOU WHISPERIN’ FOR!?’
say = gets.chomp
if say == say.upcase
date = rand(21) + 1930
puts 'NO, NOT SINCE ’ + date.to_s + ‘!’
end
end
Does ruby look at things and work its way down from the beginning or
does it
do one thing and then go back and look at something else and then do it?
Am I
making sense what I’d like to know? The reason I ask is, if I try the
script
below, I keep getting both ‘answers’ from ‘grandma’.:
puts ‘(Say Hi to grandma)’
say = gets.chomp
while say != ‘BYE’
puts ‘HUH!? SPEAK UP! WHAT’RE YOU WHISPERIN’ FOR!?’
say = gets.chomp
if say == say.upcase
date = rand(21) + 1930
puts 'NO, NOT SINCE ’ + date.to_s + ‘!’
if say == ‘BYE’
puts ‘BYE, BYE!’
end
end
end
**Here’s the output:
Hi gramma
HUH!? SPEAK UP! WHAT’RE YOU WHISPERIN’ FOR!?
HI GRAMMA!
NO, NOT SINCE 1949!
HUH!? SPEAK UP! WHAT’RE YOU WHISPERIN’ FOR!?
It looks like my script is going back ‘up’ and then coming back down
all
over again. Does that make sense and does anyone understand what I’m
asking
now about ‘how’ Ruby ‘reads’ a script or whatever? If I can wrap my mind
around the ‘how’ it works, I might be able to figure out these exercises
a
little easier…then again, the answer I get might just confuse me more,
lol.
Thanks,
JB