Got Stuck with While Loops


#1



Hi all,

Since November 2015, I have started coding on Codecademy and PHP is the first language I'm learning. But I have a problem with the While Loops now. I got stuck at the While loop syntax. When I have finished my exercise, I press 'Save & Submit' Code and thereafter the system is always crashing. My syntax is completely black as well and I cannot see anything.

Does anyone know how to solve this problem? You would really help me because when I have finished this exercise, I have finished the complete course at the same time.

Thanks in advance for your help.

Klaas


Replace this line with your code.


#2

Hi can you post your code?


#3

Hi, and welcome. That's probably the nicest thing I could say because what comes next you might not like. Don't take this course. Seriously, don't. Not yet, at least.

Start with HTML and CSS. Everything centers around the UI which is an HTML/CSS environment. The behaviors we program in, but the core document is HTML. Learn these thoroughly.

PHP is not about behaviors, but server responses. JavaScript is the client side language that handles behaviors in the browser. PHP concerns itself with composing responses that the server can send down with each request from the client. In most cases it is part of a template.

Until one has mastered the client side, there is no point thinking of the server side. It will be hellish to learn this stuff backwards. Switch courses and return to this one after you have HTML, CSS and JavaScript under your belt. You'll thank yourself in the long run.


#4

Hi wizmarco,

Sure I can, here it is:







<?php
$loopCond = true;
while($loopCond == true){
echo "

The loop is running.

"; }
?>
</body>


#5

Hi mtf, thanks for your feedback. Yes I am busy with PHP because when I'm good enough at it, I can work at the company of a mate of mine. But I will make a beginning with HTML and CSS because that is indeed more important as you said.

Thanks again for your feedback!


#6

Hi first you shoud put your string between <p></p> tag like that

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

then in your while statement you should put the $loopCond and set it to false under the echo satement in the whille loop
Hope that could help you and remov


#7

Hi, I have done all the things you said. But now I have another problem. When I click 'save and submit code', it does not respond. I have refreshed my browser repeatedly and I have also tried three different browers. But that doesn't help either. Do you know how to solve that problem?

Thanks in advance

Klaas


#8

can you take a screenshot of your code?


#9

Here it is:


#10

This is the error I get: Oops, try again. expected p:first-child text to be equal to The loop is running. but got

And when I thought my code was good, I pushed the button 'Save and submit code' but it does not work, the blue gear is rotating forever.

Thanks in advance for your help.


#11

Since PHP recognizes truthy,

    while ($loopCond) {
        // code
        $loopCond = false;
    }
    echo "<p>And now it's done.</p>";

#12

Thnx mtf! I already tried it like that myself, but the blue button didn't respond en a few minutes ago it did, so I have finished the course!

But thanks anyway!


#13

I'm having the very sme problem.
What is the fix mates??


#14

Can someone find a solution? Getting stuck at the same place.


#15

Hi inside the while condition try to add one = like that

while ($loopCond == true) {
...

#16

Done it both ways, it throws error.


#17

you should remove the space between <p> and "The..." to your string in the while loop


#18

Ah, nice catch! Thanks.


#19

And since PHP recognizes truthy values,

while ($loopCond) {

}

is sufficient. No comparison necessary.


#20

This thing worked. Thanks @mtf