# Re: "Goto line" function?

**URL:** <https://www.ruby-forum.com/t/re-goto-line-function/88361>\
**Category:** Ruby\
**Created:** [March 10, 2007, 1:21am UTC](https://www.ruby-forum.com/t/re-goto-line-function/88361 "2007-03-10T01:21:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joseph\_Schiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ba9def/32.png) [@Joseph\_Schiller](https://www.ruby-forum.com/u/Joseph_Schiller)\
**Post date:** [March 10, 2007, 1:21am UTC](https://www.ruby-forum.com/t/re-goto-line-function/88361/1 "2007-03-10T01:21:35Z")

</div>

Hi,

Fortunately the “goto” has been deprecated. It always results in  
spaghetti code. Check out ‘case’ control structure instead. You may  
want to think through the program flow so that you have each possibility  
and a default case for unanticipated situation. You will need to wrap  
your code inside the case structure. It’s mo’ better solution than  
coding ad hoc.

i = 3  
case i  
when 1, 2…5  
print “1…5\n”  
when 6…10  
print “6…10\n”  
end

Regards,

Joe

----- Original Message ----  
From: Paul van Delst [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: ruby-talk ML [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Friday, March 9, 2007 6:40:05 PM  
Subject: Re: “Goto line” function?

Helgitomas G. wrote:

> 1. puts ’ ’
> 2. 
> 
> ```
> (the program continues)
> 
> ```
> 
> 3. 
> 4. BUT if answer == ‘no’
> 5. 
> 
> ```
> goto.line.7 (And skip the rules, just restart it and begin
> 
> ```
> 
> from line 7.)
> 
> What is the command? I know it’s not “goto.line.X” but what is it? “back  
> to line.X”? “goto.lineX”? What is the command?

Addressing just the loop/goto issue, how about summat like:

#!/usr/bin/env ruby  
done=false  
until done  
puts ’ ’  
puts ’ ’  
puts ‘**’  
puts ‘\*\* (Rules of the program) \*\*’  
puts '**’  
puts ’ ’  
puts ‘Ohh, hello there! What are you named many names?’  
names = gets.chomp  
if names == ‘2’  
puts ’ ’  
puts ‘Are you named two names?’  
puts ’ ’  
answer = gets.chomp  
done = true if answer == ‘yes’  
end  
end  
#This is where “the program continues”  
puts ‘the end’

This gives me the output:

lnx:scratch : blah.rb

* * *

\*\* (Rules of the program) \*\*

* * *

Ohh, hello there! What are you named many names?  
2

Are you named two names?

no

* * *

\*\* (Rules of the program) \*\*

* * *

Ohh, hello there! What are you named many names?  
2

Are you named two names?

yes  
the end

cheers,

paulv

–  
Paul van Delst Ride lots.  
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
