Re: While-else

From: Date: Thu, 03 May 2007 12:36:00 +0000
Subject: Re: While-else
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-29145@lists.php.net to get a copy of this message
This fails the "Make PHP code easier to read" test I think. But it passes the "I'm a lazy programmer" test with flying colors! ;-) I mean seriously, what real value does this add to the language? Its just syntactic sugar to save yourself a few keystrokes. On 5/3/07, Andrew Brampton <andrew@bramp.freeserve.co.uk> 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: <?php 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. thanks Andrew -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#29145) next »