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:
> <?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.

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?

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

Reply via email to