This forum is now read-only. Please use our new forums at discuss.codecademy.com.

While Loops in PHP Forum

View Course » View Exercise

1365 points
52d8043f52f863a9ef00242d_794711961
Submitted by
CodeLikeJesus
almost 4 years ago

[resolved] 6/7 Parse Error: Whats going on ?????

heres my code can someone help me i don't see any errors .... Have i lost my abilities ???

<!DOCTYPE html>
<html>
    <head>
        <title>Much a do-while</title>
    </head>
    <body>
    <?php
        $loopCond = true;
        do{ 
            echo "<p>The loop ran even though the loop condition is false.</p>";

        }
        while ($loopCond):
            echo "<p>Now the loop is done running.</p>";
            $loopCond = false;
        endwhile;
    ?>
    </body>
</html>

10 votes

permalink

Hi,

You're mixing up your syntax by trying to incorporate "endwhile" in a "do-while" loop.

In a do-while loop, the code should end with "while ($loopCond);"

You also need to move "$loopCond = false;" into the body of the loop, otherwise it will run as an infinite loop. The final code will look like this:

<!DOCTYPE html>
<html>
<head>
    <title>Much a do-while</title>
</head>
<body>
<?php
    $loopCond = true;
    do{ 
        $loopCond = false;
        echo "<p>The loop ran even though the loop condition is false.</p>";

    }
    while ($loopCond);

        echo "<p>Now the loop is done running.</p>";

?>
</body>

1581 points
52ce7e9a282ae3d7c9001d2e_115777321
Submitted by
blue_falcon
almost 4 years ago

4 Comments

52d8043f52f863a9ef00242d_794711961 CodeLikeJesus almost 4 years ago

Mhmm Thanks :p

Picture Yoshiki Takeda almost 4 years ago

this is great answer!! awsome!!

40cff1c912cd9ff93131a4d6a56c6f03?s=140&d=retro JRfeng over 3 years ago

Awsome answer!

C0ab52132a94037383e9af5cd6b5be47?s=140&d=retro Deji Ajayi over 3 years ago

$loopCond = true; was not in the original code