RE: [PHP] For Loops and Variables??

From: Date: Tue, 16 Sep 2003 23:07:26 +0000
Subject: RE: [PHP] For Loops and Variables??
Groups: php.general 
Request: Send a blank email to php-general+get-162799@lists.php.net to get a copy of this message
John Ryan <mailto:celticfc@iol.ie> on Saturday, September 13, 2003 9:26 AM said: > When I use for loops, at the start of each iteration, the variables > hold the values from the last loop. You're doing it wrong then (I think). 1. You should always initialize your loop counters. i.e. $x = 0; while($x < 100) { $x++; } 2. Don't use the same counter name in all your loops. This is bad: for($x=0;$x<100;$x++) { for($x=0;$x<100;$x++) { echo "i'm going to go on forever!!"; } } This Is Good(tm): for($x=0;$x<100;$x++) { for($x=0;$x<100;$x++) { echo "Me happy now!!"; } } Does that help? Chris.

« previous php.general (#162799) next »