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

While Loops in PHP Forum

View Course » View Exercise

562 points
5182e5c177244a39a5000674_656263046
Submitted by
Manolo
over 4 years ago

What's Wrong with my code ?

<!DOCTYPE html>


A loop of your own



<?php
//Add while loop below
$myLoop = true;
while($myLoop):
echo "My loop is working!";
endwhile;
?>


3 votes

permalink

Because it's an endless loop. You need to make it end somehow

457 points
518556a4b6ad82a53e000a21_901691013
Submitted by
Zach Saucier
over 4 years ago

4 Comments

5182e5c177244a39a5000674_656263046 Manolo over 4 years ago

Ok, Thanks Zach

Ea3fe3c0cf212034f0b77e6c0835950e?s=140&d=retro blackatlanta over 4 years ago

to end, did you put $myLoop = "false" before endwhile?

Also, doesn't $myLoop's value need to be in quotes?

518556a4b6ad82a53e000a21_901691013 Zach Saucier over 4 years ago

The "$myLoop = false;" is what I meant by needing to make it end, or any other way of making it end. And no, $myLoop's value does not need to be in quotes, that is only for when $myLoop is a String variable, which it is not. It is a boolean variable

Ea3fe3c0cf212034f0b77e6c0835950e?s=140&d=retro blackatlanta over 4 years ago

Thanks Zach!


3 votes

permalink

<!DOCTYPE html>


A loop of your own



<?php
$wcount = 1;
echo $wcount;

while ($wcount < 5) {
$wflip=rand(0,1);

if ($wflip == 1);
{
    $wresult[] = "wTales,";
} 
else 
:
    $wresult[] = "wHeads,";
endwhile

$wcount = $wcount + 1;

}
print_r ($rwesult)

?>
?>

This is what I did to get the right answer. This code should work.

102 points
C539ccb3bf4bd92ccdba0a22b3f4f423?s=140&d=retro
Submitted by
VictoriaC.
over 4 years ago

1 Comment

524838e8abf82174930038b4_774268263 Abu-Bakr almost 4 years ago

odd


0 votes

permalink

<!DOCTYPE html>


A loop of your own



<?php
$wcount = 1;
echo $wcount;

while ($wcount < 5) {
$wflip=rand(0,1);

if ($wflip == 1);
{
    $wresult[] = "wTales,";
} 
else 
:
    $wresult[] = "wHeads,";
endwhile

$wcount = $wcount + 1;

}
print_r ($rwesult)

?>
?>

This is what I did to get the right answer. This code should work.

102 points
C539ccb3bf4bd92ccdba0a22b3f4f423?s=140&d=retro
Submitted by
VictoriaC.
over 4 years ago


0 votes

permalink

I typed this and it gave me the right answer..

<?php
$lastminuite = true;
while($lastminuite):

    echo "<p>Helloww whats upp</p>";
    $lastminuite =false;
endwhile;
?>

876 points
9b1b7d5a6f4026eaefded5b14fc99b56?s=140&d=retro
Submitted by
deep.row4
over 3 years ago


-11 votes

permalink

hi

83 points
1c28b937b8047a2b5a1f2bc6425a83ed?s=140&d=retro
Submitted by
SddfdssAL
over 4 years ago

1 Comment

1fd1601a6654f4f1164c8bc7b19f2358?s=140&d=retro Bryan over 2 years ago

hi.