im not too sure in there where you want it, but there are a few structures you can use when inside loops to either break out of them or continue with the next iteration. if you didnt guess by the bold, the words are break and continue. break will cause a loop to quit, even if the terminating condition hasnt been met, and continue will cause it to automatically loop back to the top without executing the rest of the contents.
here are examples
while (1) {
//perform a calcuation of some sort
if ( some_condition == FALSE ) break;
//more calculations and maybe output here
}
thats an infinite loop by the outside, but you can see inside, we check for a condition, and if its false, the break statement jumps to the outside of the loop
while ( $x < 500 ) {
//some calculations
if ( $x == magic_number ) {
$x++;
continue;
}
// more code here
in that example, when x = the magic number, we increment x and then call continue, which puts us back at the beginning of the loop, and the code below "more code here", does not get executed for that iteration.
hope that helped.