On 28/04/07, Pelle Ravn Rosfeldt <[EMAIL PROTECTED]> wrote:
Hi there.

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!";
}
?>
---------------------

Python & Perl already have this function. So why not PHP?

The 'but everyone else is doing it' argument is particularly weak when
it's not actually accurate.

$ man perlsyn
The following compound statements may be used to control flow:
[...]
          LABEL while (EXPR) BLOCK
          LABEL while (EXPR) BLOCK continue BLOCK

$ perl -le '$i = 99; while ($i < 10) { $i++; } else { print "Oh..."; }'
syntax error at -e line 1, near "} else"

I can't see any point in it myself. It doesn't read naturally and it
doesn't add anything that you don't get by preceding your
while with a simple if statement.

-robin

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to