Page 1 of 1

for loops & moving to next loop

Posted: Sun Aug 21, 2005 10:01 am
by taldos
Hi,

Very basic question, but I've forgotton how to do this:

Code: Select all

foreach ($my_array as $temp_key => $temp_value)
{
       if($condition)
            //stop this loop and go to next
      else 
             //continue with script

}
As you can see I want to skip the remainder of the script in a loop if a condition is met. I don't think break or return would work here. Must be some sort of next function.

Posted: Sun Aug 21, 2005 10:09 am
by nielsene

Code: Select all

foreach() {
  if ($con) continue;
 // rest of loop, no else is really needed as continue moves to the next item immediately.
}

Posted: Sun Aug 21, 2005 10:12 am
by taldos
Merci Beaucoup. Thanks :-)