I have a loop that is doing some error checking in my PHP code. Originally it looked something like this…
foreach($results as $result) { if (!$condition) { $halt = true; ErrorHandler::addErrorToStack('Unexpected result.'); } doSomething(); } if (!$halt) { // do what I want cos I know there was no error }
This works all well and good, but it is still looping through despite after one error it needn’t. Is there a way to escape the loop?
You are looking for the break statement.