for loops & moving to next loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
taldos
Forum Commoner
Posts: 39
Joined: Mon Aug 23, 2004 8:47 am
Location: Philadelphia

for loops & moving to next loop

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
}
taldos
Forum Commoner
Posts: 39
Joined: Mon Aug 23, 2004 8:47 am
Location: Philadelphia

Post by taldos »

Merci Beaucoup. Thanks :-)
Post Reply