Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Enhancing a Simple PHP Application Paginating a List: Model and View Introducing While Loops

stage 8 challenge 1

Write a while loop to display the numbers 1 through 9, all on one line with no spaces: 123456789. (You will need a counter variable to keep track of the number of times the while loop has executed; name that variable $i.)

while.php
<?php

$i = 0;
while ($i.){
$i += 123456789;
}






?>

1 Answer

Hugo Paz
Hugo Paz
15,622 Points

Hi MUZ,

You have a couple of errors in your code. I'll post the solution and give you an explanation.

$i = 1;
while($i <= 9){
echo $i;
$i++;
}

So we want the numbers 1 to 9 so we initialize $i with 1.

We then need to set the condition that exits the while loop - once $i is larger than 9, the last number we want to display, the loop ends.

We echo the variable $i.

We increment the variable $i.