Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:29160 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40186 invoked by uid 1010); 3 May 2007 15:34:37 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 40171 invoked from network); 3 May 2007 15:34:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2007 15:34:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=ceo@l-i-e.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ceo@l-i-e.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain l-i-e.com from 67.139.134.202 cause and error) X-PHP-List-Original-Sender: ceo@l-i-e.com X-Host-Fingerprint: 67.139.134.202 o2.hostbaby.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from [67.139.134.202] ([67.139.134.202:1334] helo=o2.hostbaby.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/77-27633-A010A364 for ; Thu, 03 May 2007 11:34:35 -0400 Received: (qmail 12962 invoked by uid 98); 3 May 2007 15:34:33 -0000 Received: from 127.0.0.1 by o2.hostbaby.com (envelope-from , uid 1013) with qmail-scanner-2.01 (clamdscan: 0.88.7/3198. Clear:RC:1(127.0.0.1):. Processed in 0.077764 secs); 03 May 2007 15:34:33 -0000 Received: from localhost (HELO l-i-e.com) (127.0.0.1) by localhost with SMTP; 3 May 2007 15:34:33 -0000 Received: from 216.230.84.67 (SquirrelMail authenticated user ceo@l-i-e.com) by www.l-i-e.com with HTTP; Thu, 3 May 2007 10:34:33 -0500 (CDT) Message-ID: <38877.216.230.84.67.1178206473.squirrel@www.l-i-e.com> In-Reply-To: <00a001c78d55$8362b810$0a00a8c0@Andrew> References: <82F935820ADAF34089CFF7E6C49655B4013F3D48@GTSPOST1.gts.dk> <35014.216.230.84.67.1178133032.squirrel@www.l-i-e.com> <00a001c78d55$8362b810$0a00a8c0@Andrew> Date: Thu, 3 May 2007 10:34:33 -0500 (CDT) To: "Andrew Brampton" Cc: internals@lists.php.net Reply-To: ceo@l-i-e.com User-Agent: Hostbaby Webmail MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] While-else From: ceo@l-i-e.com ("Richard Lynch") On Thu, May 3, 2007 2:34 am, Andrew Brampton wrote: > ----- Original Message ----- >> On Sat, April 28, 2007 1:03 pm, Pelle Ravn Rosfeldt wrote: >>> Is it possible to make a "while" with a "else"-statement in PHP6? >>> I know that it's not the first time this subject is up, but my >>> research >>> shows that a lot of people miss it. Including me. >>> >>> Here's an example of what I mean: >>> --------------------- >>> >> $i = 1; >>> while ($i <= 10) { >>> echo $i++; >>> } else { >>> echo "The while couldn't be executed!"; >>> } >>> ?> >>> --------------------- > > I have wanted to use this kind of syntax a couple of times, for > example: > while ($line = mysql_fetch_array(...)) { > echo $line; > } else { > echo 'Sorry no records'; > } > ?> > > Otherwise I would write the above code as a while + a if. > > However I'm unsure if this syntax should be put into PHP, but I > thought I'll > just post a example of when I would use it. I can understand how it works now, and where you'd use it... And I still don't care for it... I mean, 'else' just doesn't go with 'while', to me... And you rarely need something as convoluted as the other example. while ($line = mysql_fetch_array(...)){ echo $line; //not really right, btw... :-) } if (!mysql_num_rows(...)){ echo "no records"; } So, really, it just makes confusing PHP code, that doesn't seem to save much, in most real-world cases I can think of. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?