Your first while loop


#1


I keep on redoing this code and tried several versions. I copied and refreshed the page and pasted it. The output box states the last echo "and now it's all done" but not the echo before it.
The error message: Oops try again.. You did not fill out the loop correctly.


Replace this line with your code. 

<!DOCTYPE html>
<html>
    <head>
		<title>Your First PHP while loop!</title>
	</head>
	<body>
    <?php
	$loopCond = true;
	$loopCond = 1;
	while ($loopCond <! 5) {
		//Echo your message that the loop is running below
		echo "<p>Tne number is $loopCond <br> </p>";
		$loopCond++;
	
		$loopCond = false;
	}
	echo "<p> And now it's done. </p> ";
	
    ?>
    </body>
</html>


#2

I see several mistakes in your code:

First
Why did you declare two times $loopCond
Please use only this one $loopCond = 1;

Second
Comparison Operators <! what do you expect here ?
Read this Comparsion Operators

Third
Your loop will run as long as the while expression evaluates to TRUE
How did you reach a end with your code?

You count $loopCond up with $loopCond++; and after that you set $loopCond to FALSE. If your comparsion operator would be right you will never reach 5

After all your code should look more like this:

$loopCond = 1;
	while ($loopCond <5) {
		//Echo your message that the loop is running below
		echo "<p>Tne number is $loopCond </p>";
		$loopCond++;
	}

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.