From: David Vallner Date: 2006-08-16T06:52:24+09:00 Subject: Re: goto function? On Tue, 15 Aug 2006 23:05:10 +0200, fabsy wrote: > I want the script to start over again.. for example.. > When the user made an input and pressed return I want the script to > "restart" or jump to the beginning.. > Let me introduce you to my good friend: structured programming. I'm sure you'll get along marvelous once you get to know each other. The BASIC construct of "goto" is rightfully considered harmful for programs above a certain complexity. It's not present in Ruby in any direct way that would let you jump around a program's structure arbitrarily. (Actually, that's a lie, but I'll hold the continuations for the sake of simplicity.) If you want a script to start over, the easiest way is to put all the logic of the script into a function / procedure / whatever, and repeatedly call that one in a loop like Darren and Robert indicated. If you want the script to react to user input, you could for example do: def do_stuff_with_file(r_file) # Most of your original code goes here. end should_print_file = true while should_print_file # Better way to avoid file not found errors - you're creating a completely # useless temporary file as a workaround. File.open('file') { | r_file | do_stuff_with_file(r_file) } if File.exist? ('file') puts('Print file again? [y/n]') should_print_file = (gets[0] == 'y') # Flaky bit, should be more forgiving. end David Vallner