goto function?

P

Pit Capitain

Simen said:
There's no way to do:

goto :a
label :a

Right, but with some evil Ruby code, this is possible:

irb(main):001:0> require "goto"
=> true
irb(main):002:0> with_goto do
irb(main):003:1*
irb(main):004:1* puts 1
irb(main):005:1> goto :b
irb(main):006:1>
irb(main):007:1* label :a
irb(main):008:1> puts 3
irb(main):009:1> goto :c
irb(main):010:1>
irb(main):011:1* label :b
irb(main):012:1> puts 2
irb(main):013:1> goto :a
irb(main):014:1>
irb(main):015:1* label :c
irb(main):016:1> puts 4
irb(main):017:1>
irb(main):018:1* end
1
2
3
4
=> nil
irb(main):019:0>

No, I won't show the implementation yet. See
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/202387

Regards,
Pit
 
N

N Okia

Ah very clever. Corrupting the minds of the innocent by introducing
bad programming practices to the language.

This reminds me of a conversation I had with one of my junior
programmers on a project back in the 80's. He argued that since the C
language specification included the GOTO statement it was perfectly
fine to use it. I pointed out that my Jeep had a roll bar, but that
didn't mean I should use it!
 

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

No members online now.

Forum statistics

Threads
474,210
Messages
2,571,091
Members
47,692
Latest member
RolandRose

Latest Threads

Top