in reply to if statement used in foreach-loop?

The entire difference is centered on one thing - that "next" statement. "next" statement leads you to the next iteration (when the condition is satisfied), and skips the rest steps of this particular iteration. In some sense, your second piece of code is saying the opposite of your first piece (from the print statement's point of view).

Peter (Guo) Pei