Programming in the small WAS: [PHP-WIN] escape loop on timeout

From: Date: Tue, 22 May 2001 11:47:21 +0000
Subject: Programming in the small WAS: [PHP-WIN] escape loop on timeout
Groups: php.windows 
Request: Send a blank email to php-windows+get-7816@lists.php.net to get a copy of this message
> for ($x=0; $x < 1000000000; ++$x) { > > if ( (0 === ($x % 1000)) && (time () - $start_time) > $timeout) > break; > > echo ($x, '<br>'); > } I am a little bit conservative when it comes to use the break-statement, and the rule of thumb I uses is; any singular block should have one defined entry point an one defined exit point. A break statement will break that rule. According to this rule I would prefer to write it like: bTimeOut = false; for ($x=0; $x < 1000000000 && !bTimeOut; ++$x) { /* some statements what so ever.... */ if ( (0 === ($x % 1000)) && (time () - $start_time) > $timeout) { bTimeOut = true; } } Now the code have one entry point and one exit point. Also there is a small little extra bonus with this: it's quite clear from the style of the code what the intention to do is.

« previous php.windows (#7816) next »