From: Patrick Gundlach Date: 2005-12-05T23:07:34+09:00 Subject: increasing counter whithin loop? Hi, a very basic question... I'd like to output the sequence "a b d e", by testing if the current element is == "b" then skip the next element and continue the loop. The obvious solution doesn't look rubyish to me, how could I use the first or second attempt to get the desired solution? Patrick -------------------------------------------------- a=%w( a b c d e ) # incorrect, outputs "a b c d e" 0.upto(a.size - 1) do |i| puts a[i] if a[i]=="b" # skip next element # but i won't get affected i += 1 end end # incorrect, outputs "a b c d e" for i in 0...a.size puts a[i] if a[i]=="b" # skip next element # but i won't get affected i += 1 end end # incorrect, outputs nothing... is there a next_next ? a.each do |elt| puts elt if elt=="b" # skip next element # ?? end end # this one works, but is ugly i=0 while i < a.size puts a[i] if a[i]=="b" # skip next element i += 1 end i += 1 end