how to use "goto" method inruby?

D

dare ruby

Dear all,

As a part of my task in some places, as like in other languages i was
supposed to use "Goto" method. Is there any way to use goto in ruby?

like in other languages,

goto <labelno>
goto <labelname>


Thanks in advance,
Martin
 
B

Brian Mitchell

Dear all,

As a part of my task in some places, as like in other languages i was
supposed to use "Goto" method. Is there any way to use goto in ruby?

like in other languages,

goto <labelno>
goto <labelname>

There isn't a goto feature in Ruby, however, it isn't hard to get the
same sort of flow control out of more appropriate features. For loops
there is break, next, and redo. For general unwinding there are
exceptions (ie. begin-rescue/ensure/else) and catch-throw pairs (not
to be confused with exceptions). There are also delimited
continuations (via callcc), though I doubt you will need this feature.
Finally, what I recommend in most of these cases is refactoring. While
goto can be a very clear way to describe things, it is a rare
occasion. It is even more rare that another alternative ruby provides
isn't at least as clear.

If you can provide an idea of what you are thinking you need goto for,
go ahead and post some code and ruby-talk can hammer it out into a
beautiful master piece. If you still really want to have goto, I think
there is a library that emulates label based jumps... check RAA or
Rubyforge.

Brian.
 
R

Robert Klemme

As a part of my task in some places, as like in other languages i was
supposed to use "Goto" method. Is there any way to use goto in ruby?

like in other languages,

goto <labelno>
goto <labelname>

I do know nothing about this assignment of yours but I seriously
question the competence of the person that required you to use "goto".
You can read up tons of arguments out there on the web and even on this
list against using this form of ancient flow control.

Kind regards

robert
 
J

John Joyce

I do know nothing about this assignment of yours but I seriously
question the competence of the person that required you to use
"goto". You can read up tons of arguments out there on the web and
even on this list against using this form of ancient flow control.

Kind regards

robert
And there you can start to see part of why the assignment is to use
goto in different languages...
 
R

Robert Klemme

And there you can start to see part of why the assignment is to use
goto in different languages...

You mean, someone is trying to teach the awfulness of "goto" by making
pupils use it until it hurts? Interesting approach... :)

Cheers

robert
 
H

has

And there you can start to see part of why the assignment is to use  
goto in different languages...

Perhaps it's the CS equivalent of asking the new guy to fetch a left-
handed screwdriver?

has (still looking for that glass hammer...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top