You are here: RE: [PHP] Unnecessary if statement? Programming technique « PHP « IT news, forums, messages
RE: [PHP] Unnecessary if statement? Programming technique

Posted by "Jared Williams" on 12/06/05 17:36

Hi,
Why not

for ($i = 0; $i < 1000000/100; ++$i)
{
for ($j = 0; $j < 100; ++$j)
{
// do something standard
}
// do something special for this occurence
}


Jared

> -----Original Message-----
> From: Steve McGill [mailto:steve@bluearena.com]
> Sent: 06 December 2005 10:18
> To: php-general@lists.php.net
> Subject: [PHP] Unnecessary if statement? Programming technique
>
> Hi everyone
>
> Quick question:
>
> If I have such a loop:
>
> <?
> for($i=0;$i<1000000;$i++) {
> if($i==100) {
>
> }
> // do something standard
> }
> ?>
>
> In this case it seems such a waste that the if() statement is
> done 999999 times when it's not needed. Is there any obvious
> trick that I am missing?
> I'm not sure how taxing a simple if() statement is on a
> server, maybe it's negligible, or is it something to worry about?
>
> Something which I'd prefer NOT to do:
>
> <?
> for($i=0;$i<100;$i++) {
> // do something standard
> }
>
> // do something special for $i = 100
>
> for($i=101;$i<1000000;$i++) {
> // do something standard
> }
> ?>
>
> as I would have have to either keep two copies of the code or
> write a function just for this purpose, which hardly seems worth it.
>
> Thanks to anyone who takes the time to think about my
> question and/or respond.
>
> Best wishes,
>
> Steve McGill
>
> --
> PHP General Mailing List (http://www.php.net/) To
> unsubscribe, visit: http://www.php.net/unsub.php
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация