How to use "goto" method inruby?

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

On Dec 18, 2007 11:08 PM, dare ruby [email protected] wrote:

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.

This was thunk up way back in 2003:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/72922

(Its amazing what google can turn up).

Of course this does beget the question: why would you ever want to??

On 19.12.2007 05:08, dare ruby wrote:

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

On Dec 19, 2007, at 1:45 AM, Robert K. wrote:

“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…

On 22.12.2007 15:03, John J. wrote:

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.

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… :slight_smile:

Cheers

robert

On 22 Dec, 14:03, John J. [email protected]
wrote:

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…)