PHP while loop getting stuck


#1

Hi Guys,

This is in regards to the issue that I've been facing lately. While working on Module 6 chapter 4, the code just won't get compiled and after sometime it says "The code took a long to compile".
Here is the snippet of the code:

$myAge= 24;
$myDadAge= 57;
while():
echo "My dad is ofcourse elder than me!";
endwhile;
can somebody please help ?


#2

What is your while() condition?


#3

oh sorry I forgot to mention it here. This is my while condition:
while($myAge < $myDadAge) :


#4

The above is not a while expression as much as an if statement condition.

if ($myAge < $myDadAge) {
    echo "My dad is of course older than me!";
}

'elder' is not an adjective, but a noun, btw.

The state will never change, so the loop will run indefinitely.

A while loop depends on a state change inside the loop. Without that there is no way out, save for, break (or return if the loop is inside a function).

while ($myAge < $myDadAge):
    echo "My dad is of course older than me!";
    break;
endwhile;

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.