Re: incrementing in a for loop

From: Date: Tue, 13 Sep 2005 09:28:27 +0000
Subject: Re: incrementing in a for loop
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-222261@lists.php.net to get a copy of this message
Peppy wrote:
I've searched online and am unable to find how to increment by more than one in a for loop. for ($i = 1; $i <= 6; $i++) { Is it possible to increment $i by 5?
Everyone has responded with the correct answer, but you do realize that this loop will only run twice? It will print 1, then 6. If you change it to $i < 6, then it will print 1. And just because its Tuesday, and if you happen to be using PHP 5.0.0+: $numbers = range(1,100,5); foreach($numbers as $number) { echo $number."\n"; } And now, back to your regularly scheduled programming....

« previous php.general (#222261) next »