# need understanding

Page **1** of **1**

## need understanding

$x = 1;while ($x <= 50) {

echo "<p>This text is repeated 50 times</p>";

$x = $x + 1;

}

?>

1 is stored as the value for the variable $x, right?

Then you used a while loop and set the condition for the loop to be that the value of the same variable, $x can be less then or equal to 50, right? How am I doing so far?

Then you used the string function echo to write a string to the server. This is what the browser will show.

The initial value of $x is "1", then after the string function echo you change the value of $x to be $x+1; therefore, in plain English, "the initial value of $x is 1 and while the condition of $x is <= 50, echo "This text is repeated 50 times" under the additional condition that $x is going to continually be added to by the integer of 1."

What if you didn't add the $x = $x + 1;?

Would there be an error due to an undefined status, or would the website just go on to infinitY?

Almost scared to try it...

I think I understand. Let me know if any of my reasoning is off. I just want to understand so that this is easier to me. I could memorize it, but I like the puzzle.

Thanks,

Alan

## Re: need understanding

Okay, so I did it, and at first it was cool because the text kept repeating over and over and I scrolled down for a while. But then the screen went all white. Don't know what that is all about, but I x'd out really quick.## Re: need understanding

Yep. It will just continue to write "This text is repeated 50 times" (because the variable $x remains under 50) till the scripts time out.- Andreas, HTML.net

--

Show some love for HTML.net on Twitter, Facebook and Google: Use the buttons on top of all pages.

Show some love for HTML.net on Twitter, Facebook and Google: Use the buttons on top of all pages.

Page **1** of **1**