'reply' never gets a chance to change.

Try putting your gets for reply inside the while loop at the bottom, so the
student has a chance to change their input.

Try this:

#start loop
while reply != 'yes'
  puts reply + ' ? What!?'
  if reply == 'yes'
    break
  else
    reply = gets.chomp
  end
end
On Oct 11, 2011 8:28 AM, "Dennis Nguyen" <zerofiftysix / gmail.com> wrote:

> Hey there, I'm new to this forums as well as being new to Ruby. I
> decided to slowly learn ruby since I always wanted to learn a
> programming language. But I need some help to understand looping.
>
> I'm using Chris Pine's Learn to Program book and I've been playing
> around with the exercises, trying to expand the and make them do things
> beyond the original programming. But I just don't understand looping.
>
> Pine says that to make a program loop you have to give a 'while'
> condition that's always true. And then provide a way to break out of the
> loop.  My sample program is a teacher asking a student his name and if
> his name isn't capitalized then she'll reprimand him. If his reply isn't
> "yes" then she'll keep repeating his reply.
>
> ------------------
> puts 'What is your name, young man?'
> name = gets.chomp
>
> If name == name.capitalize
>   puts 'Please take a seat, ' + name.capitalize + '.'
> else
>   puts name + '? You mean, ' + name.capitalize + ' , right?'
>   puts 'Don\'t you know how to spell your name?'
>   reply = gets.chomp
>
> #start loop
>    while reply != 'yes'
>        puts reply + ' ? What!?'
>        If reply == 'yes'
>             break
>        end
>    end
> end
> -------------
>
> And the result is just the What!? part being repeated over and over
> again infinitely. So clearly I don't understand loops.  Any insight?
>
> And sorry if this is an obvious mistake. I studied science in school,
> not computer science or logic but I'm trying! Thanks for any help you
> guys can give! :-)
>
> --
> Posted via http://www.ruby-forum.com/.
>
>