Lonny Eachus wrote:
>
> Manish, your break is working. But it is breaking out of your code
> block, not your "times" loop.
>
> {|win|
> puts "#{win.getClassName}\t#{win.getWindowText}"
> #p win.getWindowRect
> #p win
> if(win.getParent().hwnd == $ie.hwnd) then
> #p $ie.hwnd, win.getParent().hwnd
> popupwin=win
> p "Found appropriate parent...Breaking"
> break
> end
> }
>
> If I am not mistaken, this block amounts to an "iterator controlled
> loop". So "break" will get you out of this block, but if you want out
> of your times loop, you will have to do "break break".
>
> Lonny Eachus
> ==========
>
>> Subject:
>> [Wtr-general] not exactly watir but a ruby question
>> From:
>> Manish Sapariya <[EMAIL PROTECTED]>
>> Date:
>> Fri, 11 Aug 2006 15:28:36 +0530
>>
>>
>> Hi,
>> How do break out of x.times loop.
>>
>> 10.times do
>> findWindowLike(nil, /^Microsoft Internet Explorer$/, //) {|win|
>> puts "#{win.getClassName}\t#{win.getWindowText}"
>> #p win.getWindowRect
>> #p win
>> if(win.getParent().hwnd == $ie.hwnd) then
>> #p $ie.hwnd, win.getParent().hwnd
>> popupwin=win
>> p "Found appropriate parent...Breaking"
>> break
>> end
>> }
>> p "Waiting for one sec for diaog to show up"
>> sleep 1
>> end
>>
>> My break in the if condition, when I find if the child is indeed the
>> child of my ie window, is not working as expected.
>>
>> Is this correct ruby usage?
>> Can anyone suggest any other way to retry my waiting mechanism or the
>> child dialog to appear which is spawned by my IE browser.
>>
>> Thanks and Regards,
>> Manish
> ------------------------------------------------------------------------
>
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
Or, you could use a simple throw-catch pair.
% irb
irb(main):001:0> catch :done do
irb(main):002:1*
irb(main):003:1* 10.times do |x|
irb(main):004:2*
irb(main):005:2* [1,2,3].each do |y|
irb(main):006:3* throw :done if x == 4 && y == 2
irb(main):007:3> puts "#{ x } : #{ y }"
irb(main):008:3> break if y == 2
irb(main):009:3> end
irb(main):010:2>
irb(main):011:2* end
irb(main):012:1>
irb(main):013:1* end
0 : 1
0 : 2
1 : 1
1 : 2
2 : 1
2 : 2
3 : 1
3 : 2
4 : 1
=> nil
irb(main):014:0>
... so yeah, I didn't see the internal block the first time ... it will
only stop the most internal iterator ...
A throw-catch will bail to whatever level you define.
jd
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general