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

While Loops in PHP Forum

View Course » View Exercise

692 points
55f6bbb9937676b0aa00059e_129087668?awsaccesskeyid=akiajkz7qvqfd72xnj3q&expires=1506298077&signature=sheebnnmd5il7fflcdcoqugiujo%3d
Submitted by
Darkhorse
about 2 years ago

While loops- 2/7 - What am I doing wrong here? (Freezes)

My code:

<?php
$loopCond = true;
while ($loopCond == true){
//Echo your message that the loop is running below
echo "The loop is running.";
$loopCond == false;
}
echo "And now it's done.";

Crashes then I can't log in due 'bad gateway'
Even the forum's crashing now
(Checked on reddit -not the only one)

I tried adding $loopCond = rand(true,false);
$loopCond == false;
Not working.


0 votes

permalink

why did you change the $loopCond = flase; into $loopCond == false;
It is not necessary to compare, we must declare.

And the crash comes because you make a infinite loop!

BR
D.

1409 points
588b2ac3e1281365f0000133_918398059
Submitted by
Codmakr
almost 2 years ago

3 Comments

51c14e598c1ccc92c1006609_222499189 Amrita Khurana Matta almost 2 years ago

while ($loopCond == true){
//Echo your message that the loop is running below
echo "The loop is running.";
$loopCond = false;
}
echo "And now it's done.";
?>

588b2ac3e1281365f0000133_918398059 Codmakr almost 2 years ago

That is the right syntax

51c14e598c1ccc92c1006609_222499189 Amrita Khurana Matta almost 2 years ago

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