[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Go LABEL

Xx Xx

12/24/2008 5:48:00 AM

Can we do a " go label " in ruby just like in asm? i cant find any
example or documentation about this...

for example...
if()
some codes
go LabelA

else
some other codes
go LabelB

end


LabelA:

codes


LabelB:

codes
--
Posted via http://www.ruby-....

11 Answers

RubyTalk@gmail.com

12/24/2008 6:03:00 AM

0

goto

http://raa.ruby-lang.org/project/...



On Tue, Dec 23, 2008 at 9:48 PM, Xx Xx <limhuisian@hotmail.com> wrote:
> Can we do a " go label " in ruby just like in asm? i cant find any
> example or documentation about this...
>
> for example...
> if()
> some codes
> go LabelA
>
> else
> some other codes
> go LabelB
>
> end
>
>
> LabelA:
>
> codes
>
>
> LabelB:
>
> codes
> --
> Posted via http://www.ruby-....
>
>

Joel VanderWerf

12/24/2008 6:11:00 AM

0


How surreal... someone named RubyTalk is posting to ruby-talk and
instructing us to goto a project called ruby-goto. :P

RubyTalk@gmail.com wrote:
> goto
>
> http://raa.ruby-lang.org/project/...
>
>
>
> On Tue, Dec 23, 2008 at 9:48 PM, Xx Xx <limhuisian@hotmail.com> wrote:
>> Can we do a " go label " in ruby just like in asm? i cant find any
>> example or documentation about this...
>>
>> for example...
>> if()
>> some codes
>> go LabelA
>>
>> else
>> some other codes
>> go LabelB
>>
>> end
>>
>>
>> LabelA:
>>
>> codes
>>
>>
>> LabelB:
>>
>> codes
>> --
>> Posted via http://www.ruby-....
>>
>>


--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Xx Xx

12/24/2008 6:36:00 AM

0

Cant download from the link http://raa.ruby-lang.org/project/...

Link broken?

--
Posted via http://www.ruby-....

Robert Klemme

12/24/2008 11:58:00 AM

0

On 24.12.2008 07:36, Xx Xx wrote:
> Cant download from the link http://raa.ruby-lang.org/project/...

IMHO "goto" is the worst tool you can use. One of the alternatives is
catch and throw

catch :foo do
....
throw :foo
....
throw :foo, any_value_you_like
....
end

Another helpful construct is "case" which can be used in two forms

case value
when condition
....
else
end

case
when expression
....
else
end

If you give us more information about the problem you are trying to
solve we might be able to come up with better solutions.

Cheers

robert

Codeblogger

12/24/2008 12:26:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

Hi,

I agree on the case/when statement. But I don't think throw/catch is a true
alternative. It should be reserved for error handling only.

Regards,
Nicolai

Robert Klemme

12/24/2008 3:11:00 PM

0

On 24.12.2008 13:26, Codeblogger wrote:
> I agree on the case/when statement. But I don't think throw/catch is a true
> alternative. It should be reserved for error handling only.

No, for error handling you use "raise" and "rescue". Please pay close
attention to how "catch" and "throw" work, especially the fact that you
can use a second argument to "throw" to pass an object (presumably the
result of a calculation).

Cheers

robert

Phlip

12/24/2008 3:22:00 PM

0

Robert Klemme wrote:

> No, for error handling you use "raise" and "rescue". Please pay close
> attention to how "catch" and "throw" work, especially the fact that you
> can use a second argument to "throw" to pass an object (presumably the
> result of a calculation).

Then just use return.

(-:

--
Phlip

Bertram Scharpf

12/24/2008 5:55:00 PM

0

Hi Xx,

Am Mittwoch, 24. Dez 2008, 15:36:27 +0900 schrieb Xx Xx:
> Cant download from the link http://raa.ruby-lang.org/project/...
>
> Link broken?

Just googling:
<http://raa.ruby-lang.org/cache/ruby-goto/ruby-goto.....

As the author himself admits
(<http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk...),
this is more a puzzle than of any functional avail.

You should be glad not to be tempted practising this dangerous
programming style. I did not miss the goto statement in any
language for about twenty-five years. Be confident.

Merry Christmas to all!

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

Robert Klemme

12/25/2008 9:40:00 AM

0

On 24.12.2008 16:21, Phlip wrote:
> Robert Klemme wrote:
>
>> No, for error handling you use "raise" and "rescue". Please pay close
>> attention to how "catch" and "throw" work, especially the fact that
>> you can use a second argument to "throw" to pass an object (presumably
>> the result of a calculation).
>
> Then just use return.

If it can be used that would definitively my first choice. Sometimes it
can't and in these - admittedly rather rare - circumstances you should
rather use catch throw than goto IMHO.

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end

Stefan Rusterholz

12/25/2008 11:47:00 AM

0

Bertram Scharpf wrote:
> Hi Xx,
>
> You should be glad not to be tempted practising this dangerous
> programming style. I did not miss the goto statement in any
> language for about twenty-five years. Be confident.
>
> Merry Christmas to all!
>
> Bertram

I used goto to implement a parser for ISO 8601 (in C, generated by ruby)
and it is very handy for that. It's just too easy to implement a
statemachine with gotos. But besides generated code (which isn't
intended to be very readable) I do agree that goto is a bad choice.
I think it's just as bad to call a tool all-evil as to use a tool in the
wrong place.

Regards & merry christmas
Stefan

--
Posted via http://www.ruby-....