freelance84 Posted July 26, 2011 Share Posted July 26, 2011 This seems like such an obvious thing, but i cant seem to find the answer... foreach($directoryArray as $directory) { if($dir == 'horse' && $directory == 'farm') { //stop just this iteration } //carry on doing stuff } I know i could just simply put nothing in that if and follow it with an else it would do the job... however, sometimes i find i want to add something like this to a script i already wrote, which may sometimes be very complex and it would be handy to add a simple 'stop just this iteration' without out an if and else... Does this exist? Quote Link to comment https://forums.phpfreaks.com/topic/242854-break-just-this-iteration-but-continue-the-loop/ Share on other sites More sharing options...
AyKay47 Posted July 26, 2011 Share Posted July 26, 2011 you can use the PHP continue statement Quote Link to comment https://forums.phpfreaks.com/topic/242854-break-just-this-iteration-but-continue-the-loop/#findComment-1247376 Share on other sites More sharing options...
freelance84 Posted July 26, 2011 Author Share Posted July 26, 2011 Ahhhh, of course! The dusty memories of my php book come flooding back. i remember learning this but never found a use for it, up until now. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/242854-break-just-this-iteration-but-continue-the-loop/#findComment-1247379 Share on other sites More sharing options...
AyKay47 Posted July 26, 2011 Share Posted July 26, 2011 no problem, it's similar to the break; statement but continues the loop instead of breaking it completely.. Quote Link to comment https://forums.phpfreaks.com/topic/242854-break-just-this-iteration-but-continue-the-loop/#findComment-1247380 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.