Lucky_Nl
(Lucky Nl)
1
I have 2 blocks .i want exit innerblock and outer block if condition
failed
gnerally break will exit from innerblock
a=[1,2,3,4,5,6]
b=[5,2,3]
a.each do |e|
puts e
b.each do |q|
break if q==e
end
end
here if q==e.it should exit from b and a blocks
···
--
Posted via http://www.ruby-forum.com/.
a=[1,2,3,4,5,6]
b=[5,2,3]
catch :done do
a.each do |e|
puts e
b.each do |q|
throw :done if q==e
end
end
end
# >> 1
# >> 2
···
On Mon, Feb 6, 2012 at 1:43 AM, Lucky Nl <lakshmi27.u@gmail.com> wrote:
I have 2 blocks .i want exit innerblock and outer block if condition
failed
gnerally break will exit from innerblock
a=[1,2,3,4,5,6]
b=[5,2,3]
a.each do |e|
puts e
b.each do |q|
break if q==e
end
end
here if q==e.it should exit from b and a blocks
--
Posted via http://www.ruby-forum.com/\.
Robert_K1
(Robert K.)
3
"e.it" is a Groovyism. We're in the realms of Ruby here. 
Question is, what do you want to achieve? Chances are that you want
#find for this use case:
irb(main):001:0> a=[1,2,3,4,5,6]
=> [1, 2, 3, 4, 5, 6]
irb(main):002:0> b=[5,2,3]
=> [5, 2, 3]
irb(main):003:0> a.find do |e|
irb(main):004:1* puts e
irb(main):005:1> b.include? e
irb(main):006:1> end
1
2
=> 2
But what problem are you trying to solve?
Kind regards
robert
···
On Mon, Feb 6, 2012 at 8:43 AM, Lucky Nl <lakshmi27.u@gmail.com> wrote:
I have 2 blocks .i want exit innerblock and outer block if condition
failed
gnerally break will exit from innerblock
a=[1,2,3,4,5,6]
b=[5,2,3]
a.each do |e|
puts e
b.each do |q|
break if q==e
end
end
here if q==e.it should exit from b and a blocks
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/