"Your First While Loop" doesn't work, just like all the previous PHP lessons


#1

PHP has some major problems. I hope someone fixes it.

The following is my while loop code which don't work. Can someone check it please?

<!DOCTYPE html>
<html>
    <head>
		<title>A loop of your own</title>
        <link type='text/css' rel='stylesheet' href='style.css'/>
	</head>
	<body>
    <?php
	
    $loopCount = 0;
    while ($loopCount < 4) {
        echo "<p>Iteration number: {$loopCount}</p>";
        $loopCount ++;
    }
    ?>
    </body>
</html>

#2

@mario71
Can you explain us more what you are trying to get? So far, I don't see any error in the code you printed out.


#3

Because it's a while loop, and you initialized to zero, your first iteration will be $loopCount == 0 , and then 1, then 2, then 3 ...is that what you want?

My guess would be that PHP is interpreting your curly braces around the variable loopcount as a "scalar variable" .

sidenote: I personally think initializing to 1, and setting variable condition to =< 4 would be more useful, but I don't know what the instructions say...


#4

<?php
$loopCond = true;
while ($loopCond == true){
echo "the loop is running";//Echo your message that the loop is running below

	$loopCond = false;
}
echo "<p>And now it's done.</p>";
?>

i am stuck here despite I do get the right output but still can not go to the next step and gives me the below error.

(( Oops, try again. expected p:first-child text to be equal to The loop is running. but got And now it's done. ))

can someone please help me with this ???


#5

Issue resolved. thanks