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

While Loops in PHP Forum

View Course » View Exercise

4165 points
56426a1bd3292f0d74000683_604739418
Submitted by
Alex C
over 4 years ago

Common Problems #Read Me

So i noticed many people are having difficulties with this exercise. Hopefully this will help!

1st Common mistake:
Check your while loop syntax is correct:

while(condition){
}

2nd check you have a ; at the end of every code statement like this:

while(condition){
echo "Hey"; // You need a semi colon here
}

The 3rd common mistake is that you are meant to echo the statement with <p> tags like the instructions say. It should be:

echo "<p>The loop is running.</p>";

Not

echo "The loop is running.";

This is very important and is why some of you are getting the error to do with p:first-child


4th common mistake, make sure you dont have an infinite loop as it will crash your browser!

This is bad as the condition never changes:

$condition =  true;
while ($condition) {
 echo "Hey";
}

You need to make sure that the condition being evaluated in the while loop is changed within the loop. Like so:

$condition =  true; // setting $condition to true (it is a Boolean)
while ($condition) { // Runs when $condition (see below tip)
 echo "Hey"; // echo's with a semi colon at the end!
$condition = false; // changes $condition so the loop doesnt run forever.
}

In your while loop you only need $condition not $condition = true because $condition is a Boolean so is true or false, therefore when $condition is set to true the loop runs because the condition evaluates to true, and when it is set to false the loop doesnt run.


5th Check your spelling and capitalization, the correction tests are case sensitive so
echo "The Loop is Running"; would not work, because of the Cap's on "Loop" & "Running".


Hope these tips help!
Please post below if you require any more help.

Thanks,
Alex


86 votes

Best answer

permalink

I would be very happy and grateful when it would be possible to see Common Problems #Read Me text in every lessons forum questions.

Thank you!

984 points
46c5125b88743e83095f07962af2acae?s=140&d=retro
Submitted by
Vigipoti
over 4 years ago

23 Comments

56426a1bd3292f0d74000683_604739418 Alex C over 4 years ago

Ha that would be great :) I'm working with some other mods to try and get more like this! Thanks

5037e89cf1099b000200429f_8406699 Khalid Robinson about 4 years ago

Thanks Alex this helped out.

Picture Matthew Pell about 4 years ago

That was about as good an explanation as could have possibly been given. Thank you!

5308290e52f863a3da000d80_485012632 Nicco Meow about 4 years ago

y it no work

1ff65209a9624d01467a86fd03259b54?s=140&d=retro Lionessa about 4 years ago

Oh, I see, unlike the first lesson's example, instead of

while ($loopCond = true)
it should be
while ($loopCond) with nothing else in the parenthesis.

Why the difference? Why is there no qualification on $loopCond this time?

Picture Don Vasaschi about 4 years ago

thanks Alex C

A46513416585a6c66162b948eedf001a?s=140&d=retro Badtz Maru almost 4 years ago

thanks

99f27dee09b7862231a2de32ec644e5c?s=140&d=retro Bill Eisenhamer almost 4 years ago

And yet it still won't let me move to the next lesson. "Seems I have not filled in my loop condition correctly". WTF? Here's what I have done per you notes! Did I do a typo?
<?php
$loopCond = true;
while ($loopCond){
//Echo your message that the loop is running below
echo "The loop is running.";
$loopCond = false;
}
echo "And now it's done.";
?>

99f27dee09b7862231a2de32ec644e5c?s=140&d=retro Bill Eisenhamer almost 4 years ago

and it runs fine in the interpreter.

99f27dee09b7862231a2de32ec644e5c?s=140&d=retro Bill Eisenhamer almost 4 years ago

I refreshed 3 times. Ran fine in interpreter again. Still claims an issue. Maybe my browser is caching something.........
Bingo, complete reset of code and refresh of browser. IT was stuck! Damn.

Browser is Chrome,, btw.

Dd289647de158a584c3256045245bdcd?s=140&d=retro Joris.Vergauwen almost 4 years ago

your curly brace "}" should come after "echo "And now it's done."

So you get:

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

548f74b776b8fe172800008c_853418265 Petrovic Nikola almost 4 years ago

I have a problem on Completing the Loop, I think I've did everything ok but it wont let me pass to the next chapter. Here is my code:
<?php
$loopCond = false;
do {
echo "The loop ran even though the loop condition is false.";
}
while ($loopCond == true);

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

52789f3af10c605aa7005d5e_861971994 nikcherk over 3 years ago

I have this code, but something is still wrong. Can anybody point at my mistakes?
<?php
$loopCond = 1;
while ($loopCond < 4)
{

echo "<p>The loop is running.</p>";
$loopCond++;


}
?>

B13465219263fa8ce885889a9f77a94b?s=140&d=retro Shnikers over 3 years ago

+nikcherk
try doing while ($loopCond==1), and there's no need for $loopCond++.
instead, do $loopCond = 2 at the end like this:
<?php
$loopCond = 1;
while (6==6){
//Echo your message that the loop is running below
echo "The loop is running";
$loopCond = false;}
echo "And now it's done.";
?>

B13465219263fa8ce885889a9f77a94b?s=140&d=retro Shnikers over 3 years ago

how did this get 32 votes...? It just said "thanks" and yet another comment below this one said thanks but only was 2 votes. C'Mon guys!

Picture patslee6 over 3 years ago

we're thanking bc we agree that we would like to see common problems in every text. Not rly that hard to understand...

B13465219263fa8ce885889a9f77a94b?s=140&d=retro Shnikers over 3 years ago

voting isn't always agreeing, but I see your point...

17cbab7c6c6ae517c1cbc783a8f8045a?s=140&d=retro alexkjr1 over 3 years ago

Thanl you !

939d2c448982926ee5347fe5d20d87af?s=140&d=retro DatrixTSW almost 3 years ago

I have tried these suggestions and not one of them help to end the infinite loop errors I keep getting with the code. So, I don't agree on common problems #readme on each section if they don't help.

54e5e2c776b8fecec20015e8_251773967 Unathi Gxarisa almost 3 years ago

true

5474bcdb282ae34795003088_870766035 Sheraz Afridi almost 3 years ago

thanks alot

B6dda8fb88a5323bac3f545f76c91def?s=140&d=retro shankargounder over 2 years ago

is still not
is still not work for me

54908e7195e378595d000180_505516900 erikkli over 2 years ago

extremely helpful :) thank you bretheren


26 votes

permalink

The only way I was able to get it to validate was by leaving everything that wasn't PHP out of my answer. For example:

<?php
    $loopCond = true;
    while ($loopCond) {
        echo "<p>The loop is running.</p>";
        $loopCond = false;
    }
    echo "</p>And now it's done.</p>";
?>

NOT

<!DOCTYPE html>
<html>
<body>
<p>
<?php
    $loopCond = true;
    while ($loopCond) {
        echo "<p>The loop is running.</p>";
        $loopCond = false;
    }
    echo "</p>And now it's done.</p>";
?>
</p>   
</body>
</html>

132 points
Dcde258e3e7db7efbfffd91372a3d445?s=140&d=retro
Submitted by
ryanvold2
almost 4 years ago

21 Comments

0d9aaae3955426da0b101632371490a1?s=140&d=retro pmhindurwa about 3 years ago

Thanks. This is the only solution that worked after trying everything else. There is really something wrong with this PHP lesson right from the beginning.

543d264e52f863e15c00273c_608938884 David Douglas about 3 years ago

Thanks, I've been frustrated with this session for awhile. This is the only thing that worked. There are so many bugs in this PHP lesson!!!!

Df7e7a3af5da99696d088db91bc7cb36?s=140&d=retro UmTheMuse about 3 years ago

Thanks, this worked for me, too. Btw, you don't want the p tags surrounding your code anyway. That's why you add them within the echoes

6e221d0b57209177d790bd61bb5eba0f?s=140&d=retro Raidah Nudrat about 3 years ago

Thanks, that was very helpful. I was losing my mind wondering about what I was doing wrong.

87f13cf9082d08f5a0fada5a2fb9e9d9?s=140&d=retro LaurenJScherm about 3 years ago

THANK YOU! This is the only thing that worked on my end. Everything else resulted in the same "p:first-child" error, even after spell-checking and monitoring the tag placements. This section took obnoxiously long to figure out.

577cf3314c432ced0f000636_783933343 Whahaewi about 3 years ago

Thanks very much, ryanvold2.

9ce726a007ce64c120dcb04d9c6f271a?s=140&d=retro asmartbuilders about 3 years ago

Thanks!

Acebd99b84f094641742e64a8ec61cc5?s=140&d=retro sanjibon about 3 years ago

Last problem i don't understand
plz helo me.....

Acebd99b84f094641742e64a8ec61cc5?s=140&d=retro sanjibon about 3 years ago

help me.........

9ce726a007ce64c120dcb04d9c6f271a?s=140&d=retro asmartbuilders about 3 years ago

Hi, sanjibon just paste it and see what happen.
<?php
$loopCond = true;
while ($loopCond) {
echo "The loop is running.";
$loopCond = false;
}
echo "And now it's done.";
?>

B0bb0e8322ed090720c9c9a6f6279651?s=140&d=retro scriptNinja75113 about 3 years ago

pleez can you explain why this worked and my code didnt...this is the whole point of learning..i have been effin with this code for weeks...below is my code..
<!DOCTYPE html>


Your First PHP while loop!


<?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.";
?>

B0bb0e8322ed090720c9c9a6f6279651?s=140&d=retro scriptNinja75113 about 3 years ago

i have already corrected the ($loopCond==true) n set it to just ($loopCond)..still same error

Picture Abdullah Al-Mamun almost 3 years ago

I got stuck at this lesson for weeks now. Thanks for the solution. I think there's something wrong with this lesson. I'm just happy to move on to the next lesson.

54654ba2c1ab18cc0dbd343a06177733?s=140&d=retro eL_Jay almost 3 years ago

Same-o have tried al the solutions mentioned on the Q&A forum, still not passed 2/7 :(. Since PHP works it's magic serverside it is not possible my shitty 6-y/o laptop is causing these troubles?

939d2c448982926ee5347fe5d20d87af?s=140&d=retro DatrixTSW almost 3 years ago

I tried what the common #readme said and it doesn't work for me. Obviously I don't agree with that form of help but I don't really understand why we have to get rid of all the HTML tags with this above example. Doesn't make any sense to me.

D989fb899f4942e7b5a641d9729f9fde?s=140&d=retro annetwildergmail.com almost 3 years ago

You gotta be effin kidding me!!! It did work when deleted the HTML code and only entered the PHP. Definitely a system error.

Thank you so much for your insight @ryanvold2

552a8434d3292f4bfa00038b_116619402 Swapnil Bhadade over 2 years ago

Still did not worked ! got an syntax error

Picture Dimitri over 2 years ago

Did work, thank you very much

D9f7a99b56012983b85681470ad190e5?s=140&d=retro Jessie P. over 2 years ago

Thanks! it helps

Fa68c63aa27cdad335d8627ea5bbed7d?s=140&d=retro CDTX over 2 years ago

Perhaps the bug is now fixed as I was able to complete without removing non-PHP items. The solution for me was while ($condition) not while ($condition = true).

A5ba1285e8142aa3740cc08378e41d6c?s=140&d=retro Reianna-Bryant about 2 years ago

It worked for me too, but I can't help at wondering how and why?


4 votes

permalink

Thanks. This helped.

1294 points
4237d5b4403c12eb88e5bccaba435641?s=140&d=retro
Submitted by
Waseef Akhtar
over 4 years ago


3 votes

permalink

I've been stuck on this for days and just gave up and moved on to working on the Javascript lesson. I've read through the majority of answers to this thread, tried all of the changes suggested, and I still keep getting the error: "Oops, try again. Did you put parentheses around $LoopCond?" Take a peek and see what I'm missing? This is driving me nuts!

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

876 points
Picture
Submitted by
Kay McKelly
over 2 years ago


2 votes

permalink

what has me confused is the hint section

"Add the condition $loopCond or $loopCond == true within the parentheses in line 9. (The two statements are equivalent.)"

so i used $loopcond == true and i got the infinite loop as described above, if == causes this can reference to it be removed from the hint?

784 points
Picture
Submitted by
Mark Jones
over 4 years ago

1 Comment

556dc3859113cb82cf000294_934958111 captain_caps over 2 years ago

If you really used $loopcond it could be that the error was because capitalization matters and it should have been $loopCond


2 votes

permalink

Thanks a lot!

149 points
Picture
Submitted by
Eugene Ellington
over 4 years ago


2 votes

permalink

thank you Alex!!! gosh-darned semi-colons....

1237 points
523b4ff0abf8218f6100004d_748076864
Submitted by
Red
about 4 years ago


1 vote

permalink

Thanks Alex this helped me a lot.

1008 points
51306991d089e483a100728b_480979936
Submitted by
Omar Zaffar Khan
about 4 years ago


1 vote

permalink

My browser keeps telling me I have an infinite loop while I'm in the middle of writing code.

For example:

$condition = true;
while ($condition) {
echo "Hey";
$condition = fa...... notice pops on screen telling me I have an infinite loop just before I can finish telling the loop to set $condition=false

I've tried to write the code backwards, I've tried deleting the php marks then rewriting them, nothing seems to work. As far as I can tell both of my browsers are up to date (I've tried this with google chrome and IE).

940 points
1082171b5e39e65a5dfa6306a6e4e625?s=140&d=retro
Submitted by
leif09123
almost 4 years ago

1 Comment

E814b642221d88dc1530aa484916a301?s=140&d=retro Robert Richey almost 4 years ago

The interpreter is trying to run the code as you type it. Finish writing the code the way you want and then refresh your browser page.


1 vote

permalink

i type this and it works
<!DOCTYPE html>


Your First PHP while loop!


<?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.";
?>

660 points
3d271891c5fc014aeec35f2dcb465805?s=140&d=retro
Submitted by
Nico
over 3 years ago

3 Comments

5212c1bb80ff339b22000ae0_188727294 Hugo Mejia almost 3 years ago

actually if you modify your line 11 in your code above then it passes like here:

<!DOCTYPE html>

Your First PHP while loop!

<?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.";
?>

5212c1bb80ff339b22000ae0_188727294 Hugo Mejia almost 3 years ago

I guess they really want you to use for you tu pass the lesson...at least that is how it works on my Chrome browser OS X 10.10.1

Picture Sanesh Maharaj almost 3 years ago

Thank you VERY much


0 votes

permalink

Thanks. My error is:
while(condition==true).
I think that mistake many membres were same.
Your post is useful.

369 points
51bae6448c1cccdc9e003246_254842824
Submitted by
Trio Miller
over 4 years ago

1 Comment

56426a1bd3292f0d74000683_604739418 Alex C over 4 years ago

Thanks :) Share the link around to other users :)


0 votes

permalink

Thanks Alex

683 points
67cea673ddb964518ae6c5764366ab59?s=140&d=retro
Submitted by
seb204l
over 4 years ago

2 Comments

F0f59a6c22fa1a8774366a4d9cf17e6b?s=140&d=retro tahareal over 4 years ago

Thx alot :D

9db578e55753240b99bc67ab8327ec7b?s=140&d=retro Bharat Raghuram over 2 years ago

Thanks a ton! Got stuck at while(condition==true), and finally got past it


0 votes

permalink

please think this all right, but I can not run,
Could you help me?

<!DOCTYPE html>


Your First PHP while loop!


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

44 points
Picture
Submitted by
Levy Xavier Abreu
over 4 years ago

4 Comments

5108df1e69bf01e02d002980_626456678 Steve Cummins over 4 years ago

Look at the third common mistake above

56426a1bd3292f0d74000683_604739418 Alex C over 4 years ago

@Steve +1

Dd289647de158a584c3256045245bdcd?s=140&d=retro Joris.Vergauwen almost 4 years ago

And move the closing curly brace "}" after "echo "And now it's done.";.

You should have:

$loopCond = false;
echo "And now it's done.";
}

939d2c448982926ee5347fe5d20d87af?s=140&d=retro DatrixTSW almost 3 years ago

What Joris said isn't working for me @Steve -1


0 votes

permalink

Gracias por la ayuda, y explicar los diferentes errores que pudiesemos tener!!1
Mi error, no escribir el texto que pedía dentro del bucle.

358 points
A0f039403e63f20bd0375e2c3e7e7af3?s=140&d=retro
Submitted by
José Antonio
over 4 years ago

1 Comment

66f32383bdfbf9cf75c60ca1a38b18c8?s=140&d=retro Freddy over 3 years ago

??????


0 votes

permalink

<!DOCTYPE html>


Your First PHP while loop!


<?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.";
?>


And i have followed the advice of some person wrote above,and anyway it is giving this error.
Oops, try again! expected p:first-child text to be equal to The loop is running. but got

291 points
5631023ad3292fc57400021a_214964193
Submitted by
Roman Ina
about 4 years ago

2 Comments

Faf81f65f00a9856c29d3e98532175b3?s=140&d=retro portkill about 4 years ago

Make sure the first letters in each sentence are capitalized - it's very particular!

Dd289647de158a584c3256045245bdcd?s=140&d=retro Joris.Vergauwen almost 4 years ago

Move the closing curly brace "}" after echo "And now it's done.";. You should have: $loopCond = false; echo "And now it's done."; }


0 votes

permalink

thanks a lot man..i was literally frozen looking at the screen trying to figure this out

405 points
B9b4af7d293f8c94db1d696f5a21fc1e?s=140&d=retro
Submitted by
D. Philpot
about 4 years ago


0 votes

permalink

Many thanks really helpfull! :)

38 points
A3a4a097b8360bd9508c4fcd3d35e1bc?s=140&d=retro
Submitted by
alain777
about 4 years ago


0 votes

permalink

Okay, so where did i go wrong?

<!DOCTYPE html>


Your First PHP while loop!


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

245 points
Ae102e66957a579ff29c62745a8d211d?s=140&d=retro
Submitted by
Ijem Ofili
about 4 years ago

3 Comments

57113c6114f3ef531b000126_28716191 Andy Petrzilka about 4 years ago

Use tags. For example use echo "The loop is running."; as well as at the end, echo "And now it's done.";

56426a1bd3292f0d74000683_604739418 Alex C about 4 years ago

+1 Andy, @Ijem it is the 3rd point above in the main post

Ae102e66957a579ff29c62745a8d211d?s=140&d=retro Ijem Ofili about 4 years ago

I made sure I was correct and i had the correct code but somehow the code started working today, its been refusing to run true for the past week even though I had the tags and all. well... Thanks @(Alex, Andy)


0 votes

permalink

I am on the next lesson where I create my own loop and this works in the preview window, but when I submit it says I didn't write a correct while condition which I don't understand. (and the tags are there they just don't show up)

<!DOCTYPE html>


A loop of your own



<?php
//Add while loop below
$runs = 0;
while ($runs < 3) {
echo "We still have a chance!";
$runs ++;
}
echo "We can't do it!";
?>

133 points
529f705b7c82ca41dc001038_932111126
Submitted by
Sam Meyer
about 4 years ago

2 Comments

Picture Jesse Cabaniss about 4 years ago

I'm trying to do the same thing you are except I'm putting $i = $i++ ; It's an infinite loop and I can't figure out why.

Picture Jesse Cabaniss about 4 years ago

Actually, I wrote it like yours and it worked. Not sure why it's not working for you.


0 votes

permalink

<!DOCTYPE html>


Your First PHP while loop!


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

what did I do wrong?

67 points
Picture
Submitted by
Vincent Van de Wouw
about 4 years ago

1 Comment

Picture Jesse Cabaniss about 4 years ago

You need the "echo" tag before your "loop is running" string, as well as tags


0 votes

permalink

Thank you!

465 points
Picture
Submitted by
Josh Muroki Kariuki
about 4 years ago


0 votes

permalink

I just wanted to say something before I do anything in this thread. I'm totally having problems with understanding looping and wanted to say something before I actually read this course to see what it's about. I'm going to go through the course again as well as read this forum topic tomorrow.

1151 points
5386327b8c1ccc8eb4000421_859882484
Submitted by
Froggerswim
almost 4 years ago


0 votes

permalink

I didn't forget about Codecademy. I was stuck on looping so I went to another site to get a better understanding and ended up going through there course program on PHP. I found the site very nice and even installed a apache/mysql server and am adjusting to that now. As well as I used other networks such as Freenod IRC in php channel and people I know who know PHP. Now I'm learning about PHP references, though I probably will not use references much.

I like the fact that I can sort of hop around to get a better understanding of things. Often in school if you do not understand a teacher trying to teach a concept one does not have the option to look for another teach who may explain it better (In my experience a teacher who speaks good english). The way that I would actually implement this code cademy course would be way way different now. I'd incorporate a rating system as well as videos pertaining to course that users of this site felt were helpful, in combo with the in web browser compiler.

Try out thephpbasic course back to back with codecademy course.The individual who teaches the course is also into solar technology and even made a remote controlled solar powered lawnmower.

http://thephpbasics.com/

1151 points
5386327b8c1ccc8eb4000421_859882484
Submitted by
Froggerswim
almost 4 years ago

1 Comment

53485d147c82ca051d0001ab_391424483 FAHAD SALEEM over 3 years ago

Thanks you sooo very much dear friend./.....


0 votes

permalink

I dont know whether you guys notice about "The loop is running"...

If I just type "the loop is running." in the tag and I got wrong

but if I change to "The loop is running." and I'm ready to go...

srsly?capitalize that "T" is the key? I thought it mentioned before about PHP is not that sensetive about caplital stuff

239 points
F40b4841c97414e697fd888bf7e57057?s=140&d=retro
Submitted by
Vincent Qin
almost 4 years ago

1 Comment

56426a1bd3292f0d74000683_604739418 Alex C almost 4 years ago

Im not sure about PHP but the way CC checks to see if you have it right or not is very sensitive.


0 votes

permalink

Don't forget to add a period(.) at the end of your string(The loop is running.)

987 points
52d9e6367c82cac0dc000dc8_555116947
Submitted by
William
almost 4 years ago


0 votes

permalink

thank you!! i was sooo stuck but now i've got it.

834 points
5328c149282ae3d1e00008da_981612917
Submitted by
diana
over 3 years ago


0 votes

permalink

Somebody's upset and down voted everybody on this topic cough cough GUYUS

1151 points
5386327b8c1ccc8eb4000421_859882484
Submitted by
Froggerswim
over 3 years ago

2 Comments

56426a1bd3292f0d74000683_604739418 Alex C over 3 years ago

Yeah he's really annoying on this thread so I've banned him, have a nice day sorry for any inconvenience :)

56426a1bd3292f0d74000683_604739418 Alex C over 3 years ago

You might want to tell http://www.codecademy.com/jeromethefish to watch out too and make sure he stops randomly spamming and posting rubbish.


0 votes

permalink

Thanks for all your responses :) Sorry if they have been down voted there's some not very nice people that occasionally go on these forums.

4165 points
56426a1bd3292f0d74000683_604739418
Submitted by
Alex C
over 3 years ago


0 votes

permalink

This post is not helpfull. The same text. Over, and over again.

"Oops, try again. It seems you have not filled in the loop condition correctly"

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

437 points
6468b1d38f3dd047a3c38700333e9c3f?s=140&d=retro
Submitted by
thigrand
over 3 years ago

3 Comments

56426a1bd3292f0d74000683_604739418 Alex C over 3 years ago

That code works fine try refreshing the page or maybe you are on the wrong exercise. And next time if you want help try not starting your response with an insult.

6468b1d38f3dd047a3c38700333e9c3f?s=140&d=retro thigrand over 3 years ago

There are no insult. Check in dictionary what insult mean. This topic don't work for me. I tried on 3 webbrowsers, after refreshing, coockie cleaning, code-pasting. I programming in C a bit, so it's easy to pass. But this application doesn't work correctly.

6468b1d38f3dd047a3c38700333e9c3f?s=140&d=retro thigrand over 3 years ago

And the part about always the same text was about :
"Oops, try again. It seems you have not filled in the loop condition correctly"


0 votes

permalink

I would gratefully Appreciate it if you added in the fact that it is case sensitive

example: echo "The Loop is Running"; would not work, because of the Cap's on "Loop" & "Running"....

289 points
64a640e0e1ce4c230bd0c29a787d057d?s=140&d=retro
Submitted by
Distrbd21
over 3 years ago

3 Comments

56426a1bd3292f0d74000683_604739418 Alex C over 3 years ago

Sure thing

56426a1bd3292f0d74000683_604739418 Alex C over 3 years ago

Added

64a640e0e1ce4c230bd0c29a787d057d?s=140&d=retro Distrbd21 over 3 years ago

Thanks.


0 votes

permalink

this tutorial is buggy and annoying. having this long list of feels like a bunch of excuses for not designing it well

526 points
53f386279c4e9d748600006a_91978409
Submitted by
Max Cohen
over 3 years ago

1 Comment

56426a1bd3292f0d74000683_604739418 Alex C over 3 years ago

It's not an excuse its me helping people by showing them where they may be going wrong


0 votes

permalink

This was a great post, thanks! Not a lot of people who already know how to code will go out of their way to help beginners.
I love PHP, but those semicolons do get you quite often, syntax is very important, one tiny thing is missing and your code won't work at all. Adding to that, is the fact that you have to pay very close attention to what the exercises ask you to do, so while you think your code is broken it might not be, you might be missing those html tags or that random full stop. Attention to details is very important when you are learning to code

326 points
4f914f34812fa90003016067_377693448
Submitted by
Nicola Buske
about 3 years ago


0 votes

permalink

I gave up trying to make this work correctly and wrote this instead.

<!DOCTYPE html>
<html>
    <head>
      <title>Your First PHP while loop!</title>
  </head>
  <body>
    <?php
  $loopCond = 1;
  while ($loopCond < 10){
      //Echo your message that the loop is running below
      echo "<p>The loop is running.</p>";
      $loopCond ++;
  }
  echo "<p>And now it's done.</p>";
    ?>
    </body>
</html>

I matched all of the conditions and even had it returning the correct output but it just refused to accept this plsfix.

I even tried just copying code from the people in this thread stating that their code would work.

172 points
E2151d3a7a5234711050f61c8cac1432?s=140&d=retro
Submitted by
Chamunks Arkturus
about 3 years ago

1 Comment

5822bf2c06e27e4bd084f37470bfeefa?s=140&d=retro joweb1 over 2 years ago

Try by removing $loopCond ++; and add: $loopCond = false;
Remove and relocate your bottom curly brace to below the second echo statement.
What is should do now is check if the condition is < 10 and is true.
if it is it will echo the first echo line as 1, than it will evaluate again and print 2, and so on up to 11 when it will meet not meet the condition that is to false and than exit the loop.


0 votes

permalink

a quick question: what is wrong with Allman (aka ANSI) coding style? I mean why do you not support other coding styles?

85 points
Picture
Submitted by
Stingu Gratiela
about 3 years ago


0 votes

permalink

Horrible Lesson Chapter, buggy , vague and totally out of sync with all the other excellent stuff here at Codecademy. Another chapter like this one and Ill look elsewhere for tutorials

209 points
54bd2804e39efe775100625b_135289754
Submitted by
Joe Bieniecki
almost 3 years ago


0 votes

permalink

$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>";

Error Did you add a semicolon after the echoed string?

102 points
54c7ab20d3292fa3f0002a97_189609663
Submitted by
I Dont My Name Newbie
almost 3 years ago

1 Comment

Picture Osvaldo Costa over 2 years ago

thanks................. i was having same problem


0 votes

permalink

Can you tell what I am missing in my code I am getting this error: Parse error: syntax error, unexpected '}' on line 11
<?php
$loopCond = false;
do {
echo "The loop ran even though the loop condition is false.";
} while ($loopCond);

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

1147 points
Picture
Submitted by
Vimala Venugopalan-Mark
over 2 years ago

2 Comments

Picture Vimala Venugopalan-Mark over 2 years ago

Line 11 is the } while ($loopCond);

59ebde77aa33d11ab70002c3_723331277 Guilherme Martins over 2 years ago

Same problem I'm facing :(


0 votes

permalink

Hello Alex, thank you for your patience on this course. Could you review my code, I am so stuck. Thanks.

<?php
$loopCond = true;
while ($loopCond) {
echo "The loop is running.";
}

$loopCond = false;
}
echo "And now it's done.";
?>

117 points
Fb2c346fca90821b097387365c1d0f4b?s=140&d=retro
Submitted by
ersearcy3
over 2 years ago

4 Comments

56426a1bd3292f0d74000683_604739418 Alex C over 2 years ago

I think that will be the 3rd common mistake i have listed. Do you see where it says use tags?

Fb2c346fca90821b097387365c1d0f4b?s=140&d=retro ersearcy3 over 2 years ago

I made the adjustments and before I enter anything the site says it took too long to finish check for infinite loops and it remains in a non responsive or something went click close to try again. Frustrating have to move on to something else. Next it says I'm not connected Here's my code. Thanks.

Fb2c346fca90821b097387365c1d0f4b?s=140&d=retro ersearcy3 over 2 years ago

<?php
$loopCond == true;
while (5 < 7) {
echo "The loop is running.";

$loopCond = false;
}
echo "And now it's done.";
?>

5822bf2c06e27e4bd084f37470bfeefa?s=140&d=retro joweb1 over 2 years ago

you didnt include the "And now it's done.";


0 votes

permalink

Parse error: syntax error, unexpected $end on line 18
I GOT THIS ERROR EXPLAIN THAT.

54 points
555d3e66e39efe48150000be_243241270
Submitted by
RRajBhattarai
over 2 years ago


0 votes

permalink

Case 27

<?php
$loopCond = true;
while ($loopCond) {
echo "The loop is running.";
$loopCond = false;
}
echo "And now it's done.";
?>

NOT

<!DOCTYPE html>



<?php
$loopCond = true;
while ($loopCond) {
echo "The loop is running.";
$loopCond = false;
}
echo "And now it's done.";
?>

Please check your as you started with in both cases and that will cause an error.

362 points
5822bf2c06e27e4bd084f37470bfeefa?s=140&d=retro
Submitted by
joweb1
over 2 years ago

1 Comment

5822bf2c06e27e4bd084f37470bfeefa?s=140&d=retro joweb1 over 2 years ago

Check your as you started in both cases with . That will cause you an error.


0 votes

permalink

It seems to have an infinite loop built into the question. The only way I could get this to stop crashing was to VERY QUICKLY delete 'while' whilst I wrote the rest of the code, because the page automatically runs the existing infinite loop.

Then when the rest of the code is ready - make sure you have while statement ($loopCond == true) - I added 'while' back in, ran the code and it works fine.

65 points
F157547e6d6413fbcf53d604863fa22a?s=140&d=retro
Submitted by
chrisimmediate
about 2 years ago


-1 votes

permalink

Thanks Alec

780 points
5197fd9d8ffc0ba39d0006d2_879767769
Submitted by
optymalnyX
over 4 years ago


-1 votes

permalink

Thanks, this was very helpful!

186 points
7ec19a2fbc9ba839c2928e962d5cc792?s=140&d=retro
Submitted by
felixgp
over 4 years ago


-1 votes

permalink

I've got the p tags in, and rest of the code correct too (double checked with others) but still get the p:first child error?!

392 points
780a8981593fe9e418b07c368a412da8?s=140&d=retro
Submitted by
brooksy89
over 4 years ago

3 Comments

Picture Sara Flindt Krag about 4 years ago

i've got the same problem..

5221aa79f10c60e606000680_420136815 Nicode about 4 years ago

too

56426a1bd3292f0d74000683_604739418 Alex C about 4 years ago

Sorry not getting back quickly on this one! "The loop is running." should be the exact thing you echo copy and paste it in or check for any spaces after the and a full stop at the end.


-1 votes

permalink

Thank you so much!!! This helped a lot!

1288 points
57113c6114f3ef531b000126_28716191
Submitted by
Andy Petrzilka
over 4 years ago


-1 votes

permalink

A lucid explanation! Thanks!

177 points
520a9eaff10c6082fa000185_420370782
Submitted by
Brad Yonghyun Cho
over 4 years ago


-1 votes

permalink

Thanks

588 points
1837c9e335a7bc7482fe58db5545146d?s=140&d=retro
Submitted by
yking
over 4 years ago


-1 votes

permalink

Ohh Alex my man...you are a gem! Cheers mate!

392 points
524b8f5b548c35e9470008c9_29858105
Submitted by
Mayur Makheri
about 4 years ago


-1 votes

permalink

Any reason why the following shouldn't be used, apart from the fact that it doesn't exactly match the solution? At least it works in the code previewer!

<!DOCTYPE html>


Your First PHP while loop!


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

838 points
Picture
Submitted by
Mark Thomas
about 4 years ago

8 Comments

56426a1bd3292f0d74000683_604739418 Alex C about 4 years ago

It is just good practice to make sure everything is within relevant tags i.e. the tags. For instance when you make bigger web sites not putting these tags in can mess up the formatting and you wont be able to use CSS to make "The loop is running." red for example as it doesn't have any tags to change the attributes of. Hope that makes sense!

Picture Mark Thomas about 4 years ago

hmm, apparently I fixed the tags later on without noticing that as the issue, I guess as the above code did work in the simulator. Assuming I used the relevant tags, should there be any reason to not use $loopCond <> false versus $loopCond != false ?

56426a1bd3292f0d74000683_604739418 Alex C about 4 years ago

Im not an expert by any means on php and im a bit rusty as far as im aware '<>' isn't a comparison operator so you should use != but i may be wrong.

Dd289647de158a584c3256045245bdcd?s=140&d=retro Joris.Vergauwen almost 4 years ago

move the closing curly brace "}" after echo "And now it's done.";. You should have: $loopCond = false; echo "And now it's done."; }

64a640e0e1ce4c230bd0c29a787d057d?s=140&d=retro Distrbd21 over 3 years ago

Actually it's because of "while ($loopCond <> false)" should be "while ($loopCond == true)"

64a640e0e1ce4c230bd0c29a787d057d?s=140&d=retro Distrbd21 over 3 years ago

Also Don't forget your tags in your echo statements..

544bed1d9c4e9d983100230a_525469590 Dominik about 3 years ago

There is no <>, there is !=

5822bf2c06e27e4bd084f37470bfeefa?s=140&d=retro joweb1 over 2 years ago

unless the condition is true your code will not execute. AS per your previous comments.


-1 votes

permalink

The following syntax gave me a correct "passing" output:

<!DOCTYPE html>


Your First PHP while loop!


<?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.";
}
?>

400 points
566e5337e39efe281a00000a_272242078
Submitted by
Jared
over 3 years ago

2 Comments

5212c1bb80ff339b22000ae0_188727294 Hugo Mejia almost 3 years ago

nope if I copy paste your example above I still get the "Oops, try again. It seems you have not filled in the loop condition correctly" Even thought the panel displays what you want correctly...is it possible that there is an issue on this one screen from the provider side?

5822bf2c06e27e4bd084f37470bfeefa?s=140&d=retro joweb1 over 2 years ago

you must use the same terminology and its case sensitive. In addition use it with the " correctly. Check with examples provided.


-1 votes

permalink

I realized that spacing is very important during the echo part of the code.

sorry don't mind the period's between the carroted p's, the preview wouldn't reveal the paragraph sign.

If it's

echo "<.p.> The loop is running.</.p.>";

it won't register. Well for me, because after getting it correctly, I exed out of the "way to go, start next section" box and played with the spacing.

doesn't work:

echo "<.p.> The loop is running.</.p.>"; // space after <.p.> & no space before </.p.>
echo "<.p.> The loop is running. </.p.>"; // space after <.p.> & space before </.p.>
echo "<.p.>The loop is running. </.p.>"; // no space after <.p.> & space after </.p.>

works:

echo "<.p.>The loop is running.</.p.>"; // no space after <.p.> & no space before </.p.>

I think that there should be clarification for these details. As a beginner I have been stuck for 4 days trying to figure this out without looking up the answer.

Note:

Each echo and $loopCond needs a semi colon for completion.
Curly braces should wrap the entirety of the function which includes the last echo.

332 points
53e2f9fc548c35c5140005db_995984695
Submitted by
KosmicFunk
over 3 years ago

1 Comment

5822bf2c06e27e4bd084f37470bfeefa?s=140&d=retro joweb1 over 2 years ago

Remove the full stops inside the


-2 votes

permalink

    <title>Your First PHP while loop!</title>
</head>
<body>
<?php
$loopCond = true;
while ($loopCond){
    //Echo your message that the loop is running below
    echo "<p> The loop is running</p> ";
    $loopCond = false;
}
echo "<p>And now it's done.</p>";
?>

This passed then failed??

630 points
50b2f9561a1dd911630005b6_485712392
Submitted by
seg universe
about 4 years ago

4 Comments

50b2f9561a1dd911630005b6_485712392 seg universe about 4 years ago

Any help would be appreciated

56426a1bd3292f0d74000683_604739418 Alex C about 4 years ago

You should be echoing "The loop is running." Remember the fullstop at the end and remove the space at the start. Hope that helps!

Dd289647de158a584c3256045245bdcd?s=140&d=retro Joris.Vergauwen almost 4 years ago

move the closing curly brace "}" after echo "And now it's done.";. You should have: $loopCond = false; echo "And now it's done."; }

64a640e0e1ce4c230bd0c29a787d057d?s=140&d=retro Distrbd21 over 3 years ago

Actually it's because of "while ($loopCond)" should be "while ($loopCond == true)"