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

Write a while loop to display the numbers 1 through 9, all on one line with no spaces: 123456789. (You will need a count

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 = 1;
while ($i < 10) {
    echo $i;
    $i += 1;
}

2 Answers

Codin - Codesmite
Codin - Codesmite
8,600 Points
<?php
$i = 1;
while($i < 10) {
    echo $i;
    $i++;
}
?> 

or

<?php
$i = 1;
do {
    echo $i;
    $i++;
} while ($i < 10);
?> 

Either method should be an acceptable answer.

Although I highly recommend you go back and re-watch the videos before this task as they explain how this works and you will find it is something you will most likely use a lot in the future.

Try: <?php $i <= 1; while($i < 10) { echo $i; $i++; } ?>