From: Robert Klemme Date: 2010-11-11T17:27:45+09:00 Subject: Re: help with code, new to programming On Thu, Nov 11, 2010 at 2:35 AM, john wrote: > On 09 Nov 4:31 PM, Steve Rees wrote: >> >> tell me what I need to add to loop the game as I have described above? > > i don't think you need a loop. Why do you say that? Steve explicitly asked about modifying his program so it will continue the game until the user chooses to finish. As far as I can see your program does not do that. Granted, you could do that without an explicit loop by using recursion or maybe even "retry". Still, conceptually it's still a loop even if you use another (inferior in this case because more complicated) technique to implement it. >> cat o.rb > #!/usr/bin/env ruby -w > # encoding: utf-8 > def psychic_test >  puts "I'm thinking of a number between 1 & 10." >  print "What's your guess? " >  if gets.to_i == rand(10) + 1 >    puts "ARE psychic" >  else >    puts "NOT psychic" >  end >  print "Try again? (y/n): " >  gets.chomp.first =~ /y/i ? psychic_test : exit > end > >> ruby -e "load 'o.rb'; psychic_test" You are making things unnecessary complicated here. Instead you could just do ruby 'o.rb' by adding a line "psychic_test" at the end of the script - or even better: get rid of the method completely. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/