Jump to content

The nightmare WHILE with Fatal error: Cannot break/continue 1 levels in...


Humpty

Recommended Posts

G'day Guys,

 

I am sure that the it is my lack of knowledge that got me and not understanding fully loops.

 

My issue is getting a "Fatal error: Cannot break/continue 0 levels in..." message inside of a loop.

 

The conintue; command happens inside of an IF THEN trying to continue a WHILE, however that WHILE is inside another WHILE...I believe this is where my problem may be.

 

Below is a sample of what I am doing with LOTS of code stripped out so you can see the basics.

 

$ezPhoneRun = 0;
$ezPhoneCount = 100; // this value varies.
while ($ezPhoneRun < $ezPhoneCount) {

    $ezAPCSCCounter = 0;
    $ezAPCSCDRCount = 1; //I have just added this here for your sake, the real value is a varied.
    while ($ezAPCSCCounter < $ezAPCSCDRCount) {
    
        if ($AAA != $BBB){
        	// do some code stuffs, loop
            $ezAPCSCCounter++;
            continue 0;
        }
    
    
    $ezAPCSCCounter++;
    } // END while ($ezAPCSCCounter < $ezAPCSCDRCount) {

$ezPhoneRun++;
} // end loop for isp's phone table loop

 

I have placed in some obvious things just so that you know that they are happening, $AAA and $BBB aren't important, but that is to point out that I am entering that IF THEN when the problem occurs.

 

Thanks in advance

Link to comment
Share on other sites

"The nightmare WHILE with Fatal error: Cannot break/continue 1 levels in..."

 

I've never heard of anyone with this problem, so I don't know if I would call it a nightmare, but I guess it is to you.

 

 

 

Anyway, you can't continue 0 levels.  That doesn't make sense.

Link to comment
Share on other sites

...don't know if I would call it a nightmare, but I guess it is to you.

yeah only becuase I can't work it out :D

 

 

 

Anyway, you can't continue 0 levels.  That doesn't make sense.

 

I was going to mention in the original post that I have tried using

break;

continue 0;

continue 1;

continue 2;

...all instead of continue;

but the same issue.

 

What I do not understand is the concept of 'level'.

If it refers to the looping structures (loop inside loop) or the itteration of the current loop.

 

Could you please shed some light on that so as I can understand what is happening / causing the error.

 

The other thought is that I am makeing $ezAPCSCCounter = $ezAPCSCDRCount.

but as such I would expect it to goto the begining of the loop and then decide that there is no need to loop again.

Link to comment
Share on other sites

here a little game, u got 3 chances to guess the number ...

 

we used the continue in a loop to hold the correct numbers...........

<?php

//GUESS THE NUMBER GAME 3 CHANCES.

$your_number1=89;
$your_number2=55;
$your_number3=60;


//WINNING NUMBER

$winning_number=70;

$go=1;

$stop=100;


for($i=$go; $i<$stop; $i++){

if($i==$your_number1){

	$your_number1=$i;

		continue;
}
}

for($i=$go; $i<$stop; $i++){

if($i==$your_number2){

	$your_number2=$i;

		continue;
}

}

for($i=$go; $i<$stop; $i++){

if($i==$your_number3){

	$your_number3=$i;

		continue;
}


}

if( ($your_number1 == $winning_number)
|| ($your_number2==$winning_number) || ($your_number3==$winning_number)){

echo "DAM YOU WON!";

}else{

echo "YOU LOSS!";
}
?>

Link to comment
Share on other sites

i try you code on my local wamp, and it's work OK

<?php
$AAA = 'a';
$BBB = 'b';
$ezPhoneRun = 0;
$ezPhoneCount = 100; // this value varies.
while ($ezPhoneRun < $ezPhoneCount) {

    $ezAPCSCCounter = 0;
    $ezAPCSCDRCount = 1; //I have just added this here for your sake, the real value is a varied.
    while ($ezAPCSCCounter < $ezAPCSCDRCount) {
   
        if ($AAA != $BBB){
           // do some code stuffs, loop
            $ezAPCSCCounter++;
            continue 0;
        }
   
   
    $ezAPCSCCounter++;
    } // END while ($ezAPCSCCounter < $ezAPCSCDRCount) {

$ezPhoneRun++;
} // end loop for isp's phone table loop
?>

(just setup variables $AAA and $BBB)

Link to comment
Share on other sites

(just setup variables $AAA and $BBB)

 

Yeah those 2 variables are set in the real code, I just use those 2 A and B to indicate that they were not a match for purposes of showing cut down code

 

 

 

 

 

so what else could cause it to produce this error?

 

please keep in mind that in orginial code i had continue;

but have tried break, continue 0, continue 1, and continue 2.....all of which not worked.

Link to comment
Share on other sites

<?php
$AAA = 'a';
$BBB = 'b';
$ezPhoneRun = 0;
$ezPhoneCount = 100; // this value varies.
while ($ezPhoneRun < $ezPhoneCount) {

    $ezAPCSCCounter = 0;
    $ezAPCSCDRCount = 1; //I have just added this here for your sake, the real value is a varied.
    while ($ezAPCSCCounter < $ezAPCSCDRCount) {
        if ($AAA == $BBB){
           // do some code stuffs, loop
            $ezAPCSCCounter++;
		echo 'here1';
		continue 0;
        }else {
		$AAA = 'b';
		$string = "";
	}
   
    $ezAPCSCCounter++;
    } // END while ($ezAPCSCCounter < $ezAPCSCDRCount) {
echo 'end';
$ezPhoneRun++;
} // end loop for isp's phone table loop
?>

 

I did that for test reasons, but that returned the right results.

 

Maybe your code is flawed in some way...mind posting the actual code?

Link to comment
Share on other sites

Maybe your code is flawed in some way...mind posting the actual code?

 

Indeed it was.  I don't understand why though.

 

It all revolves around an include.

 

I have put the info below as to what I did and a tad more clarification on the code (ommitted because I didn't think it would matter.)

It would still be nice to know why this happened but none-the-less I have rectified it and will look at includes next time.

 

Firstly thanks heaps to all those who helped:

premiso

Humpty

sasa

redarrow

corbin

I appreciate it.

 

This is what was happening (including the includes)

 

(start file 1)
START Loop1

include file2

(start file 2)
START Loop 2

	include file 3
	(start file 3)
		if (condition){
			continue;
			(this is where the error occured)
		}
	(end file 3)

END Loop 2
(end file 2)


END Loop1
(end file 1)

 

The only change I made was to take the code in file 3 and put it inside file 2 (instead of the include command (which by the way was working, else we wouldn't have even reached that point of code where things errored).

 

This is what I ended up with

(start file 1)
START Loop1

include file2

(start file 2)
START Loop 2

// this is where we USED TO include file 3
// this used to be start of file 3
	if (condition){
		continue;
		(this is where the error occured)
	}
// this used to be end of file 3

END Loop 2
(end file 2)


END Loop1
(end file 1)

 

I really hope that this example can help someone else if need be, and I hope that anyone reading it can understand what is happening, which is why I didn't use code other than the if...then, so that people can see this issue out of context perhaps helping them put it into context for themselves.

 

I am also leaving this open for a little while to give the opportunity for someone to mention how / why this would have happened and been fixed....it will help me (and or you) prevent this in the future.

 

I will mark as solved shortly.

 

THANKS HEAPS

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.