Re: While-else

From: Date: Thu, 03 May 2007 14:55:43 +0000
Subject: Re: While-else
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-29157@lists.php.net to get a copy of this message
On 28/04/07, Pelle Ravn Rosfeldt <PelleRR@it-college.dk> 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

« previous php.internals (#29157) next »