The while syntax in PHP is exactly the same as that in html. Just like in html, you define a variable outside the loop, and the loop continues until the condition is met. You can exit the while loop by using syntax break. Break can take a numeric value to tell PHP how many levels to break from in case of a nested while lool.
For example, if you have three foreach loops nested in each other, or for that matter three for, while, do-while, or switch structures then you can use break 3 to exit out of all three nested loops:
$times = 1;
$product = 0;
echo ("Display 5 times table as long as product is less then or equal to 25: <br><br>");
while ($times <= 10){
$product = $times * 5;
echo ("5 times ".$times." = ".$product."<br>");
$times++;
if ($product >= 25){
break;
};
};