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.
···
On Dec 18, 2007 11:08 PM, dare ruby <martin@angleritech.com> 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?
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 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?
And there you can start to see part of why the assignment is to use goto in different languages...
···
On Dec 19, 2007, at 1:45 AM, Robert Klemme wrote:
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.
You mean, someone is trying to teach the awfulness of "goto" by making pupils use it until it hurts? Interesting approach...
Cheers
robert
···
On 22.12.2007 15:03, John Joyce wrote:
On Dec 19, 2007, at 1:45 AM, Robert Klemme wrote:
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.
And there you can start to see part of why the assignment is to use goto in different languages...