Stuck in 7/7 All on your own for weeks


I keep on getting the below message for weeks.

"The program took too long to finish. Check your code for infinite loops and try again."

It even shows before I start writing.


Yeah could mean there is a bug in your code. Can you put it here


//write your do-while loop below
$roll = 0;
do {
echo $roll = rand(1,6);
} while ($roll !=6);


even I reset my code the message still pop out... I have stuck in this section for few weeks.


@joanne_ps Yes it was your code
try this here

//declare this count variable as a limiter
//in case 6 does not occur in the random numbers for
//the first n number(n is very large)
//You dont need to have it
$count = 1;

do {
	//once you start the loop you want to keep generating
	//different random numbers or else loop will run for ever
	$roll =rand(1,6);
	//Here we are limiting the number of random numbers needed
	// to till we get a 6. if we have generated 10 numbers and
	// do not have a 6 then just breakout of the loop
	//You dont necessarily need this as well
	if ($count==11){break;}
	//print out the number
	echo "roll $count is: ".$roll."<br>";
	//increment the count
} while ($roll != 6); //stopping condition

in your code

//Here you set a global roll variable awesome
// note that here we are using the '='(assign)
$roll = 0;
do {
	//this is where yo have the pitfall
	//echo is a fucntion in php (its just a built in language default)
	//when  you call functions you pass arguments to that function
	//if the function requires like the
	//int rand ( int $min , int $max ) method take in two arguments
	//you cannot be  assigning values to variables using = in method arguments

echo $roll = rand(1,6);
} while ($roll !=6);


Thanks, now I know my pitfall. But the message still pop out before I finish typing then I continue typing and submit and it took forever to load it. =(


Yeah the editor saves your code and automatically runs it :confused: try to see if you can reset the code


This worked for me, I had the same message pop up again and again and I could not progress but it didn't do it when I typed this in:

$loopCood = false;
do {
echo "IT WORKS";
} while ($loopCood);

Hope this works for you too!

7/7 - PHP -This worked but I still got an error message
Stuck in do-while

Hi Everyone,

I had the same problem caused by creating an infinite loop. Most of the suggestions in the forum didnt work, so I kept on experimenting until I tried the following.

  1. Once the page loads (with the saved code), the error message "Something went wrong..." comes up and submitting your corrected code seems to take forever. Resetting the code window or refreshing the page don't help either.

  2. Delete the portion of your code that has the loop error and replace with the correct code.

  3. Click "Full Screen" on the display window. This will display the results of your code in full screen mode (saving the corrected code in the process).

  4. Click the "Back to Editor" button at the bottom-left corner of the screen.

  5. Refresh the browser. (the corrected code will load by default)


I've found a better way --> remove browser cookies and other side and pugin data. =)


This does not work for me. It is still the same.
The message about the infinite loop re-appears.
It would be nice to have a reset button.


if I want to show many show many coins are flipping what should I do add this shows only one coin is flipping please help thanks in advance.
//write your do-while loop below
$count =0;
do {

$flip = rand(0,1);
if($count <= 6) {
    echo "roll count is: ".$flip."<br>";
  echo "<div class=\"coin\">H</div>";
	echo "<div class=\"coin\">T</div>";

while ($count == 6);   


Thanks was trying to get my old code to remove but didnt seem to work, now i tried your method and fixed it! thank you now i can continue finaly


None of these worked for me :cry: help me please i cant figure this out.

imma scrubb i just cant figure this one out but if i do ill come back and tell it so others who were stuck like me can pass on :slight_smile:


Have the same problem... Nothing helped;/


i think its glitchy i dont know... i've seen 27 different codes they all dont work but they work for others.....


what the heck are browser cookies? because if i can find out i may be able to finaly get done with this one :smiley:


This is my take on the loop:

        //write your do-while loop below
        $roll = rand(1,6);
        $rolls = 0;
        do {
            $rolls + 1;
            echo $rolls;
        while ($roll != 6);

Tells me I can't submit my code. Is it really my code or is it a bug?