PHP while loop getting stuck


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;
echo "My dad is ofcourse elder than me!";
can somebody please help ?


What is your while() condition?


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


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


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