Skip to content
PHP Logo

What is the potential issue with the loop structure in the PHP code provided?

The potential issue with the loop structure in the provided PHP code is that the loop is infinite because the condition for the while loop is always true. To fix this issue, we need to ensure that the loop will eventually terminate by updating the loop condition to check against a specific condition that will stop the loop.

php
// Fixing the loop structure to avoid infinite loop
$counter = 0;

while ($counter < 10) {
    echo $counter . "<br>";
    $counter++;
}