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


#1

What do i do after taking to the above instruction, i still get The program took too long to finish. Check your code for infinite loops and try again. what do i do


#2

Let's say that you have this code:

$myVariable = 0;
while ($myVariable < 10) {
    // body of loop
}

Make sure that somewhere in the body of loop you change the value of $myVariable. After some iterations condition $myVariable < 10 must evaluate to false.

$myVariable = 0;
while ($myVariable < 10) {
    $myVariable++;
}

#3

We cannot stress this point enough, but I think most people get it, they are just not typing fast enough to stay ahead of auto-run.

What I recommend is to build the loop backwards, so that the while conditional is last to be written, (control variable, code body and increment are first to be written) or simply introduce a deliberate syntax error so the auto-run is disabled, then build the loop, then remove the error so the program can run.