PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
djcrisp
Forum Newbie
Posts: 6 Joined: Mon Dec 01, 2008 6:25 pm
Post
by djcrisp » Mon Dec 01, 2008 6:29 pm
anyone how to use the while loop that increments through and prints every odd number between 1 and 49.
thanks in advance
any help is appreciated.
my guess is:
Code: Select all
<?php
$i = 1;
while ($i <= 49)
{
echo $i++;
}
?>
Peter Anselmo
Forum Commoner
Posts: 58 Joined: Wed Feb 27, 2008 7:22 pm
Post
by Peter Anselmo » Mon Dec 01, 2008 6:47 pm
It's better practice to use a "for" loop if you know ahead of time exactly how many iterations you'll need (as is true in this case).
Code: Select all
for( $i=1; $i<=49; $i+=2) {
echo $i;
}