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

While Loops in PHP Forum

View Course » View Exercise

481 points
Submitted by
about 5 years ago

Do/while loop "taking too long"

Hi guys.
I'm going crazy here with this. I can't figure out what's going wrong in my do/while loop. The goal is to count down from 50 by 5 but the editor never outputs what I expect it to, it just says "Program is taking too long." Can somebody help me understand what I'm doing wrong?
enter code here<!DOCTYPE html>
<title>Your own do-while</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
$number = 50;
do {
echo "{$number} ";
if ($number > 0) {
$number - 5;
$truth = true;
else {
$truth = false;
while ($truth);
echo "We're done!";

1 vote


The issue might be with this line of code:

$number - 5;

That doesn't change the value stored in your $number variable. I think you need to set $number to $number - 5 instead:

$number = ($number - 5);

Otherwise, the value of $number will forever be 50, and you'll get an infinite loop.

756 points
Submitted by
Derek Spencer
about 5 years ago


F7b57921d645a3a4c6cf0dd422c6a224?s=140&d=retro aaw588 about 5 years ago

Yup! That was the line! Another fix was changing the line to "$number -= 5; "


51774f974ae5f55804001fe1_784606691 Derek Spencer about 5 years ago

Great! Glad everything worked out.