Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Fatal error: Cannot break/continue

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.

like image 926
Georgi Georgiev Avatar asked Sep 01 '10 12:09

Georgi Georgiev


2 Answers

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

like image 87
Phill Pafford Avatar answered Oct 03 '22 17:10

Phill Pafford


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!  
like image 35
Russell Dias Avatar answered Oct 03 '22 16:10

Russell Dias