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

While Loops in PHP Forum

View Course » View Exercise

127 points
Picture
Submitted by
Adrian Parea
about 2 years ago

While Loops in PHP 6/7

Here's the code:

<!DOCTYPE html>


Much a do-while


<?php
$loopCond = false;
do {
echo "The loop ran even though the loop condition is false."; }
while ($loopCond = false);
echo "Now the loop is done running.";
?>

It shows me "Oops, try again. Did you put parentheses around $LoopCond?"
What's the trouble?


1 vote

permalink

Stuck at the same place. $loopCond = false, so you don't need to edit the condition.

<?php
    $loopCond = false;
    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>";
?>

254 points
85c8512117c769de06937455d4a89bda?s=140&d=retro
Submitted by
Hi ~
about 2 years ago

3 Comments

984b12b2c34b66b1935d3ffb4f5a63f7?s=140&d=retro asrowley almost 2 years ago

But wouldn't the while loop continue to run while $loopCond is False? Hence it would be infinite....

984b12b2c34b66b1935d3ffb4f5a63f7?s=140&d=retro asrowley almost 2 years ago

Sorry, my bad, you were right about this.

7e2df8cd09c2d86c93ead5fea19f8f51?s=140&d=retro Ekasa almost 2 years ago

Ok, so do you have an answer??


0 votes

permalink

Thanks, this helped me out.

596 points
71c15ab76387ac5ba6529a80914cede8?s=140&d=retro
Submitted by
Ruben van Houten
almost 2 years ago


0 votes

permalink

Help (PLEASE)!

Both editors show that my code is running correctly. However, i keep getting the same error message:

"Oops, try again. Did you add a semicolon after the echoed string?"

i've deleted cookies and tried different browsers AND began by using the code at the top of this page BUT also used "while ($loopCond);

Thank you in advance!

89 points
00625fba60ee979b0cd30f19c2ece046?s=140&d=retro
Submitted by
unityonehotmail.com
almost 2 years ago