Forum: Ruby exit from def?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ad6d4326183d6c395b264c541acdac01?d=identicon&s=25 Bu Mihai (mihai)
on 2007-07-12 10:47
def bla


      for i in 1 .. 5
            puts i
            for j in 1 .. 5
                    puts j
                    if j==4
                        then
                            here i want to exit the "bla" def if j==4
                            somenthing like break, but break just
interrupt
                            the 'j' for not the entire procedure; how
can i do
                            that?
                    end

       end



end


tnx
0158871402c1ecfa57952e8a379cfd10?d=identicon&s=25 Daniel Lucraft (lucraft)
on 2007-07-12 10:52
Bulhac Mihai wrote:
> def bla
>
>
>       for i in 1 .. 5
>             puts i
>             for j in 1 .. 5
>                     puts j
>                     if j==4
>                         then
>                             here i want to exit the "bla" def if j==4
>                             somenthing like break, but break just
> interrupt
>                             the 'j' for not the entire procedure; how
> can i do
>                             that?
>                     end
>
>        end
>
>
>
> end
>
>
> tnx

...

  for j in 1..5
    puts j
    return if j==4
  end

...

best,
Dan
This topic is locked and can not be replied to.