Havin problem with set the flag in loop

You should seriously consider reading http://whytheluckystiff.net/ruby/pickaxe/

And this question is suited for ruby-lang