Using EndWhile with Colon and endwhile; not working


#1


https://www.codecademy.com/en/courses/web-beginner-en-5YvPF/0/4?curriculum_id=5124ef4c78d510dd89003eb8#


I get this message: Parse error: syntax error, unexpected $end on line 19 with my code - allthough there is no line 19 and I (what I can see) have written correct coding.


<!DOCTYPE html>
<html>
    <head>
		<title>A loop of your own</title>
        <link type='text/css' rel='stylesheet' href='style.css'/>
	</head>
	<body>
     <?php
	//Add while loop below
	$random = rand(0,10);
	
	while($random != 5 )
	:
	    echo "You reached nr " . $random;
    endwhile;
    ?>
    </body>
</html>


#2

Be sure the colon is on the same line as while, with no white space.

while ():

#3

I changed the code completely, for simplisity, but it still doesn't work:







<?php
//Add while loop below
$nr = 5;

while($nr==5):
    echo "You reached nr 5";
endwhile;
?>
</body>


#4

     <?php
	//Add while loop below
	$random = rand(0,10);
	
	while($random != 5 ):
	    echo "You reached nr " . $random;
        endwhile;
    ?>

The above is your earlier code with colon in the correct place. The problem is that $random is not changing inside the loop. Will this work?

        while(rand(0,10) != 5 ):
            echo "Still not a 5";
        endwhile;

#5

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