6
if (isset($errors))  
{  
foreach ($errors as $error)  
  {  
    echo $error;  
  }    
}  
else {break 2;}  
// some more code

Outputs:

Fatal error: Cannot break/continue 2 levels  

I tried break 1, it didn't work either.

3
  • 5
    There are no loops in your code. Please post full code. Commented Sep 1, 2010 at 12:39
  • Could you please explain the context in which this code runs? Commented Sep 1, 2010 at 12:39
  • There is no need for break there because when the if fails it will continue going on regardless. Commented Sep 1, 2010 at 12:43

3 Answers 3

4
if (isset($errors))  
{  
foreach ($errors as $error)  
  {  
    echo $error;  
  }    
}  

No need to use break as you seem to want to end on the else condition. just use the above code for your errors, it will be skipped if no errors. No need for break

Sign up to request clarification or add additional context in comments.

Comments

4

Break ends the execution within a foreach, for, while, do-while or switch structure..

if (isset($errors))  
{  
foreach ($errors as $error)  
  {  
    echo $error;  
  }    
}  
else {break 2;} //there is no loop here!  

1 Comment

removed the false statement that break does not take an argument.
0

Just type break not followed with any number. But break is helpless outside of a loop / block.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.