Page 1 of 1
Label If and loop condition strucutres
Posted: Mon Nov 28, 2005 8:34 am
by kendall
can you put a label to condition and loop statements so that you can break and continue them using thier label name identifier like what happens in javascript
Kendall
Posted: Mon Nov 28, 2005 8:38 am
by Weirdan
No you can't. But you may use break <level>; and continue <level>; constructs like this:
Code: Select all
foreach(range(1,10) as $elt) {
foreach(range(1,10) as $innerElt) {
echo "[$elt, $innerElt]";
if($innerElt>5)
continue 2; // continue outer loop
}
}
Re: Label If and loop condition strucutres
Posted: Mon Nov 28, 2005 8:38 am
by Roja
kendall wrote:can you put a label to condition and loop statements so that you can break and continue them using thier label name identifier like what happens in javascript
Kendall
What you are describing is called a "labeled break", and currently php doesn't have one. However, there are discussions about
possibly adding it in php6.