From: botp Date: 2013-02-15T21:17:47+09:00 Subject: Re: skip iteration in each loop --bcaec501c558d9b4a504d5c17b98 Content-Type: text/plain; charset=UTF-8 On Fri, Feb 15, 2013 at 4:11 PM, Saurav Chakraborty wrote: > I want to skip iteration for few values depending on dynamic condition. > > Say I have a persons array [1,2,3,4,5,6,7,8] and while iterating if the > one of the values equals 2, then it should skip iteration for the next > two values (in this case it is 3 and 4) > > In this case the output should be: [1,2,5,6,7,8] > try manual iteration, ri next eg, $ cat test.rb people = (1..30).each skippers = [2,10] loop do person=people.next rescue exit if skippers.include? person person.times{person = people.next} next end p person end botp@u:~ $ ruby test.rb 1 5 6 7 8 9 21 22 23 24 25 26 27 28 29 30 kind regards -botp --bcaec501c558d9b4a504d5c17b98 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Feb 15, 2013 at 4:11 PM, Saurav Chakraborty <<= a href=3D"mailto:lists@ruby-forum.com" target=3D"_blank">lists@ruby-forum.c= om> wrote:
I want to skip iteration for few values depending on dynamic condition.

Say I have a persons array [1,2,3,4,5,6,7,8] and while iterating if the
one of the values equals 2, then it should skip iteration for the next
two values (in this case it is 3 and 4)

In this case the output should be: [1,2,5,6,7,8]

<= /div>


try manual iteration, ri next
=

eg,

$ cat test.rb
people =3D (1..30).e= ach
skippers =3D [2,10]
loop do
=C2=A0 person=3Dpeople.next rescue exi= t

=C2=A0 if skippers.include? person
=C2=A0 =C2=A0 person.times= {person =3D people.next}
=C2=A0 =C2=A0 next
=C2=A0 end

=C2=A0 = p person
end

botp@u:~
$ ruby test.rb
1
5
6
7
8
9
21
22
23
24
25<= br>26
27
28
29
30

kind regards -bo= tp


--bcaec501c558d9b4a504d5c17b98--