Req #26411 [Com]: while {} else {}

2013-02-04 Thread sebi at max-vision dot ro
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: sebi at max-vision dot ro
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

I'd love something like this: if there is at least one iteration, even with 
break or continue, don't do "else", otherwise, enter the else. 
Another great would be even better, something like 
"while(..){..}done{...}else{...}"

It could be a new keyword like "whileif".

Anyway, even the first proposed structure would be awesome.


Previous Comments:

[2013-02-04 19:56:11] bensor987 at neuf dot fr

We shouldn't use "if" or "else" for this. We should use new keywords for this. 
It seems simple to implement, but maybe they don't want this because of 
performance concerns ?


[2013-02-04 09:28:05] kjarli at gmail dot com

I don't really see a problem why not to implement this



[2012-08-23 17:09:14] bensor987 at neuf dot fr

I would like to go further in that way : "iterated". "iterated" would be parsed 
if there has been at least 1 iteration in the loop.
id . ' - ' . $array_raw[$i]->label;
}
if ( $cnt_raw > 0 ){
echo some_function( $arr_output );
} else {
echo 'Nothing to display';
}
...
?>

id . ' - ' . $array_raw[$i]->label;
} iterated {
echo some_function( $arr_output );
} none {
echo 'Nothing to display';
}
...
?>


[2012-08-22 17:36:01] bensor987 at neuf dot fr

I understand your opinion. You want to make the "else" keyword usable only when 
"false" is encountered, like in "if...else". I didn't think about this.

In that case, let's use another keyword, because this syntax is an excellent 
idea.

Why not this ? 




[2012-08-22 17:05:05] ras...@php.net

It's not that simple. Loops are repeatedly evaluated conditions. It isn't clear 
whether adding an else clause would only apply to the first evaluation or also 
subsequent ones.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2013-02-04 Thread bensor987 at neuf dot fr
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: bensor987 at neuf dot fr
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

We shouldn't use "if" or "else" for this. We should use new keywords for this. 
It seems simple to implement, but maybe they don't want this because of 
performance concerns ?


Previous Comments:

[2013-02-04 09:28:05] kjarli at gmail dot com

I don't really see a problem why not to implement this



[2012-08-23 17:09:14] bensor987 at neuf dot fr

I would like to go further in that way : "iterated". "iterated" would be parsed 
if there has been at least 1 iteration in the loop.
id . ' - ' . $array_raw[$i]->label;
}
if ( $cnt_raw > 0 ){
echo some_function( $arr_output );
} else {
echo 'Nothing to display';
}
...
?>

id . ' - ' . $array_raw[$i]->label;
} iterated {
echo some_function( $arr_output );
} none {
echo 'Nothing to display';
}
...
?>


[2012-08-22 17:36:01] bensor987 at neuf dot fr

I understand your opinion. You want to make the "else" keyword usable only when 
"false" is encountered, like in "if...else". I didn't think about this.

In that case, let's use another keyword, because this syntax is an excellent 
idea.

Why not this ? 




[2012-08-22 17:05:05] ras...@php.net

It's not that simple. Loops are repeatedly evaluated conditions. It isn't clear 
whether adding an else clause would only apply to the first evaluation or also 
subsequent ones.


[2012-08-22 16:46:52] bensor987 at neuf dot fr

"no such syntax in other languages"what do you mean ? PHP doesn't have the 
right innovate ? 

I see plenty of cases I would use this syntax. The "else"s would be triggered 
if there hasn't been any iteration in the loop. It means : less variables to 
use (so less memory usage), less code lines, etc... 

There are only advantages to this syntax (and it's pretty simple to understand, 
no KISS violation here). It's not because it isn't done by other languages that 
we shouldn't implement it.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2013-02-04 Thread kjarli at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: kjarli at gmail dot com
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

I don't really see a problem why not to implement this



Previous Comments:

[2012-08-23 17:09:14] bensor987 at neuf dot fr

I would like to go further in that way : "iterated". "iterated" would be parsed 
if there has been at least 1 iteration in the loop.
id . ' - ' . $array_raw[$i]->label;
}
if ( $cnt_raw > 0 ){
echo some_function( $arr_output );
} else {
echo 'Nothing to display';
}
...
?>

id . ' - ' . $array_raw[$i]->label;
} iterated {
echo some_function( $arr_output );
} none {
echo 'Nothing to display';
}
...
?>


[2012-08-22 17:36:01] bensor987 at neuf dot fr

I understand your opinion. You want to make the "else" keyword usable only when 
"false" is encountered, like in "if...else". I didn't think about this.

In that case, let's use another keyword, because this syntax is an excellent 
idea.

Why not this ? 




[2012-08-22 17:05:05] ras...@php.net

It's not that simple. Loops are repeatedly evaluated conditions. It isn't clear 
whether adding an else clause would only apply to the first evaluation or also 
subsequent ones.


[2012-08-22 16:46:52] bensor987 at neuf dot fr

"no such syntax in other languages"what do you mean ? PHP doesn't have the 
right innovate ? 

I see plenty of cases I would use this syntax. The "else"s would be triggered 
if there hasn't been any iteration in the loop. It means : less variables to 
use (so less memory usage), less code lines, etc... 

There are only advantages to this syntax (and it's pretty simple to understand, 
no KISS violation here). It's not because it isn't done by other languages that 
we shouldn't implement it.


[2012-08-22 10:44:30] ni...@php.net

Python has an "else" for loops, but it means something completely different.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2012-08-23 Thread bensor987 at neuf dot fr
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: bensor987 at neuf dot fr
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

I would like to go further in that way : "iterated". "iterated" would be parsed 
if there has been at least 1 iteration in the loop.
id . ' - ' . $array_raw[$i]->label;
}
if ( $cnt_raw > 0 ){
echo some_function( $arr_output );
} else {
echo 'Nothing to display';
}
...
?>

id . ' - ' . $array_raw[$i]->label;
} iterated {
echo some_function( $arr_output );
} none {
echo 'Nothing to display';
}
...
?>


Previous Comments:

[2012-08-22 17:36:01] bensor987 at neuf dot fr

I understand your opinion. You want to make the "else" keyword usable only when 
"false" is encountered, like in "if...else". I didn't think about this.

In that case, let's use another keyword, because this syntax is an excellent 
idea.

Why not this ? 




[2012-08-22 17:05:05] ras...@php.net

It's not that simple. Loops are repeatedly evaluated conditions. It isn't clear 
whether adding an else clause would only apply to the first evaluation or also 
subsequent ones.


[2012-08-22 16:46:52] bensor987 at neuf dot fr

"no such syntax in other languages"what do you mean ? PHP doesn't have the 
right innovate ? 

I see plenty of cases I would use this syntax. The "else"s would be triggered 
if there hasn't been any iteration in the loop. It means : less variables to 
use (so less memory usage), less code lines, etc... 

There are only advantages to this syntax (and it's pretty simple to understand, 
no KISS violation here). It's not because it isn't done by other languages that 
we shouldn't implement it.


[2012-08-22 10:44:30] ni...@php.net

Python has an "else" for loops, but it means something completely different.


[2012-08-22 10:29:25] hawkyhawk14 at gmail dot com

larue...@php.net
no such syntax in other languages.
-

Python has it and some versions of BASIC have it aswell.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2012-08-22 Thread bensor987 at neuf dot fr
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: bensor987 at neuf dot fr
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

I understand your opinion. You want to make the "else" keyword usable only when 
"false" is encountered, like in "if...else". I didn't think about this.

In that case, let's use another keyword, because this syntax is an excellent 
idea.

Why not this ? 




Previous Comments:

[2012-08-22 17:05:05] ras...@php.net

It's not that simple. Loops are repeatedly evaluated conditions. It isn't clear 
whether adding an else clause would only apply to the first evaluation or also 
subsequent ones.


[2012-08-22 16:46:52] bensor987 at neuf dot fr

"no such syntax in other languages"what do you mean ? PHP doesn't have the 
right innovate ? 

I see plenty of cases I would use this syntax. The "else"s would be triggered 
if there hasn't been any iteration in the loop. It means : less variables to 
use (so less memory usage), less code lines, etc... 

There are only advantages to this syntax (and it's pretty simple to understand, 
no KISS violation here). It's not because it isn't done by other languages that 
we shouldn't implement it.


[2012-08-22 10:44:30] ni...@php.net

Python has an "else" for loops, but it means something completely different.


[2012-08-22 10:29:25] hawkyhawk14 at gmail dot com

larue...@php.net
no such syntax in other languages.
-

Python has it and some versions of BASIC have it aswell.


[2012-08-22 10:09:30] ni...@php.net

Revert status change.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2012-08-22 Thread bensor987 at neuf dot fr
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: bensor987 at neuf dot fr
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

"no such syntax in other languages"what do you mean ? PHP doesn't have the 
right innovate ? 

I see plenty of cases I would use this syntax. The "else"s would be triggered 
if there hasn't been any iteration in the loop. It means : less variables to 
use (so less memory usage), less code lines, etc... 

There are only advantages to this syntax (and it's pretty simple to understand, 
no KISS violation here). It's not because it isn't done by other languages that 
we shouldn't implement it.


Previous Comments:

[2012-08-22 10:44:30] ni...@php.net

Python has an "else" for loops, but it means something completely different.


[2012-08-22 10:29:25] hawkyhawk14 at gmail dot com

larue...@php.net
no such syntax in other languages.
-

Python has it and some versions of BASIC have it aswell.


[2012-08-22 10:09:30] ni...@php.net

Revert status change.


[2012-08-22 05:56:57] larue...@php.net

no such syntax in other languages.


[2012-08-21 17:38:24] bensor987 at neuf dot fr

Why don't you go a little bit further ?

while ( $row = mysql_fetch_assoc( $result ) ){

} else for ( $i = 0; $i < $cpt; $i++ ) {

} else if ( $dude ) {

} else {

}




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2012-08-22 Thread ni...@php.net
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: ni...@php.net
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

Python has an "else" for loops, but it means something completely different.


Previous Comments:

[2012-08-22 10:29:25] hawkyhawk14 at gmail dot com

larue...@php.net
no such syntax in other languages.
-

Python has it and some versions of BASIC have it aswell.


[2012-08-22 10:09:30] ni...@php.net

Revert status change.


[2012-08-22 05:56:57] larue...@php.net

no such syntax in other languages.


[2012-08-21 17:38:24] bensor987 at neuf dot fr

Why don't you go a little bit further ?

while ( $row = mysql_fetch_assoc( $result ) ){

} else for ( $i = 0; $i < $cpt; $i++ ) {

} else if ( $dude ) {

} else {

}


[2012-04-26 02:13:36] ma-martin at hotmail dot de

Hey, i was also looking for some while {} else {} feature...
but i think it could be difficult to implement such a function in php.
Because the else{} event would start after the while{}-loop ends -> everytime 
after the last result!
think about it!




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2012-08-22 Thread hawkyhawk14 at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: hawkyhawk14 at gmail dot com
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

larue...@php.net
no such syntax in other languages.
-

Python has it and some versions of BASIC have it aswell.


Previous Comments:

[2012-08-22 10:09:30] ni...@php.net

Revert status change.


[2012-08-22 05:56:57] larue...@php.net

no such syntax in other languages.


[2012-08-21 17:38:24] bensor987 at neuf dot fr

Why don't you go a little bit further ?

while ( $row = mysql_fetch_assoc( $result ) ){

} else for ( $i = 0; $i < $cpt; $i++ ) {

} else if ( $dude ) {

} else {

}


[2012-04-26 02:13:36] ma-martin at hotmail dot de

Hey, i was also looking for some while {} else {} feature...
but i think it could be difficult to implement such a function in php.
Because the else{} event would start after the while{}-loop ends -> everytime 
after the last result!
think about it!


[2012-01-25 12:16:57] hawkyhawk14 at gmail dot com

This is a great idea. I am currently needing something like this, but however 
got 
around it using flags and making the flag true in the while. It would be alot 
more 
convenient if there was an else!

Please add this feature!!!




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2012-08-21 Thread bensor987 at neuf dot fr
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: bensor987 at neuf dot fr
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

Why don't you go a little bit further ?

while ( $row = mysql_fetch_assoc( $result ) ){

} else for ( $i = 0; $i < $cpt; $i++ ) {

} else if ( $dude ) {

} else {

}


Previous Comments:

[2012-04-26 02:13:36] ma-martin at hotmail dot de

Hey, i was also looking for some while {} else {} feature...
but i think it could be difficult to implement such a function in php.
Because the else{} event would start after the while{}-loop ends -> everytime 
after the last result!
think about it!


[2012-01-25 12:16:57] hawkyhawk14 at gmail dot com

This is a great idea. I am currently needing something like this, but however 
got 
around it using flags and making the flag true in the while. It would be alot 
more 
convenient if there was an else!

Please add this feature!!!


[2011-12-06 16:31:22] absimu at hotmail dot com

I agree. I think a while () else () will make things easier. I was researching 
and 
found out that it doesnt exist yet. 


while($row = mysqli_fetch_assoc($result)) { }

with al else I would fix it.. I am new in PHP,. I will try to find something to 
fix it. but if the while else is release in a new version that would be nice.


[2011-02-18 01:14:34] ijrbiz at gmail dot com

Highly agreed, this request would be very practical for improved coding 
structure and 
follows logical language syntax nicely.

function remove_items (&$arr, $needle) {
while ($key = array_search($needle, $arr)) {
unset( $arr[$key] );
} else return false; // No items present
return true; // Item(s) removed
}


[2010-12-19 13:08:30] trefighter2334 at aol dot com

I'd love to see something like Python's while/else logic implemented in PHP.

This logical construct would allow developers to define blocks of code in else 
{} that'd run upon a natural exit from the while(){} loop caused by said loop's 
condition becoming FALSE; however, the else {} would be skipped over if the 
loop 
exits unnaturally -- a la through a break statement or because of an exception.

It is to die for on a semi-daily basis for me (in python)... but I'm not sure 
this is what the developers above (and their examples) have in mind or not.

Either implementation would prove useful to me.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2012-04-25 Thread ma-martin at hotmail dot de
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: ma-martin at hotmail dot de
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

Hey, i was also looking for some while {} else {} feature...
but i think it could be difficult to implement such a function in php.
Because the else{} event would start after the while{}-loop ends -> everytime 
after the last result!
think about it!


Previous Comments:

[2012-01-25 12:16:57] hawkyhawk14 at gmail dot com

This is a great idea. I am currently needing something like this, but however 
got 
around it using flags and making the flag true in the while. It would be alot 
more 
convenient if there was an else!

Please add this feature!!!


[2011-12-06 16:31:22] absimu at hotmail dot com

I agree. I think a while () else () will make things easier. I was researching 
and 
found out that it doesnt exist yet. 


while($row = mysqli_fetch_assoc($result)) { }

with al else I would fix it.. I am new in PHP,. I will try to find something to 
fix it. but if the while else is release in a new version that would be nice.


[2011-02-18 01:14:34] ijrbiz at gmail dot com

Highly agreed, this request would be very practical for improved coding 
structure and 
follows logical language syntax nicely.

function remove_items (&$arr, $needle) {
while ($key = array_search($needle, $arr)) {
unset( $arr[$key] );
} else return false; // No items present
return true; // Item(s) removed
}


[2010-12-19 13:08:30] trefighter2334 at aol dot com

I'd love to see something like Python's while/else logic implemented in PHP.

This logical construct would allow developers to define blocks of code in else 
{} that'd run upon a natural exit from the while(){} loop caused by said loop's 
condition becoming FALSE; however, the else {} would be skipped over if the 
loop 
exits unnaturally -- a la through a break statement or because of an exception.

It is to die for on a semi-daily basis for me (in python)... but I'm not sure 
this is what the developers above (and their examples) have in mind or not.

Either implementation would prove useful to me.


[2008-04-09 07:51:11] ois at oisnot dot com

try {
  foreach ($nullValue as $nothing) {
echo 'valid input';
  } else {
//suppress notice
echo 'null value';
  }
  //or/and
} catch (ExceptionObjectNotIterator $e) {
  //object doesnt implement Iterator
  echo $e->getMessage();
}




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2012-01-25 Thread hawkyhawk14 at gmail dot com
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: hawkyhawk14 at gmail dot com
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

This is a great idea. I am currently needing something like this, but however 
got 
around it using flags and making the flag true in the while. It would be alot 
more 
convenient if there was an else!

Please add this feature!!!


Previous Comments:

[2011-12-06 16:31:22] absimu at hotmail dot com

I agree. I think a while () else () will make things easier. I was researching 
and 
found out that it doesnt exist yet. 


while($row = mysqli_fetch_assoc($result)) { }

with al else I would fix it.. I am new in PHP,. I will try to find something to 
fix it. but if the while else is release in a new version that would be nice.


[2011-02-18 01:14:34] ijrbiz at gmail dot com

Highly agreed, this request would be very practical for improved coding 
structure and 
follows logical language syntax nicely.

function remove_items (&$arr, $needle) {
while ($key = array_search($needle, $arr)) {
unset( $arr[$key] );
} else return false; // No items present
return true; // Item(s) removed
}


[2010-12-19 13:08:30] trefighter2334 at aol dot com

I'd love to see something like Python's while/else logic implemented in PHP.

This logical construct would allow developers to define blocks of code in else 
{} that'd run upon a natural exit from the while(){} loop caused by said loop's 
condition becoming FALSE; however, the else {} would be skipped over if the 
loop 
exits unnaturally -- a la through a break statement or because of an exception.

It is to die for on a semi-daily basis for me (in python)... but I'm not sure 
this is what the developers above (and their examples) have in mind or not.

Either implementation would prove useful to me.


[2008-04-09 07:51:11] ois at oisnot dot com

try {
  foreach ($nullValue as $nothing) {
echo 'valid input';
  } else {
//suppress notice
echo 'null value';
  }
  //or/and
} catch (ExceptionObjectNotIterator $e) {
  //object doesnt implement Iterator
  echo $e->getMessage();
}


[2003-11-29 08:59:16] elmi...@php.net

Yes, you're right, my code was wrong. Next try:

$found = false;
while ($row = mysql_fetch_assoc($result)) {
   $found = true;
   print 'Here is a result';
   ...
} 

if (!$found) {
   print 'No results found';
}


The proposed while/else syntax is indeed a bit more elegant.





The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2011-12-06 Thread absimu at hotmail dot com
Edit report at https://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: absimu at hotmail dot com
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

I agree. I think a while () else () will make things easier. I was researching 
and 
found out that it doesnt exist yet. 


while($row = mysqli_fetch_assoc($result)) { }

with al else I would fix it.. I am new in PHP,. I will try to find something to 
fix it. but if the while else is release in a new version that would be nice.


Previous Comments:

[2011-02-18 01:14:34] ijrbiz at gmail dot com

Highly agreed, this request would be very practical for improved coding 
structure and 
follows logical language syntax nicely.

function remove_items (&$arr, $needle) {
while ($key = array_search($needle, $arr)) {
unset( $arr[$key] );
} else return false; // No items present
return true; // Item(s) removed
}


[2010-12-19 13:08:30] trefighter2334 at aol dot com

I'd love to see something like Python's while/else logic implemented in PHP.

This logical construct would allow developers to define blocks of code in else 
{} that'd run upon a natural exit from the while(){} loop caused by said loop's 
condition becoming FALSE; however, the else {} would be skipped over if the 
loop 
exits unnaturally -- a la through a break statement or because of an exception.

It is to die for on a semi-daily basis for me (in python)... but I'm not sure 
this is what the developers above (and their examples) have in mind or not.

Either implementation would prove useful to me.


[2008-04-09 07:51:11] ois at oisnot dot com

try {
  foreach ($nullValue as $nothing) {
echo 'valid input';
  } else {
//suppress notice
echo 'null value';
  }
  //or/and
} catch (ExceptionObjectNotIterator $e) {
  //object doesnt implement Iterator
  echo $e->getMessage();
}


[2003-11-29 08:59:16] elmi...@php.net

Yes, you're right, my code was wrong. Next try:

$found = false;
while ($row = mysql_fetch_assoc($result)) {
   $found = true;
   print 'Here is a result';
   ...
} 

if (!$found) {
   print 'No results found';
}


The proposed while/else syntax is indeed a bit more elegant.



[2003-11-26 17:21:53] he...@php.net

Read again. Your code would always print 'No results found' while the intended 
change wouldn't.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

https://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2011-02-17 Thread ijrbiz at gmail dot com
Edit report at http://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: ijrbiz at gmail dot com
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

Highly agreed, this request would be very practical for improved coding
structure and 

follows logical language syntax nicely.



function remove_items (&$arr, $needle) {

while ($key = array_search($needle, $arr)) {

unset( $arr[$key] );

} else return false; // No items present

return true; // Item(s) removed

}


Previous Comments:

[2010-12-19 13:08:30] trefighter2334 at aol dot com

I'd love to see something like Python's while/else logic implemented in
PHP.



This logical construct would allow developers to define blocks of code
in else 

{} that'd run upon a natural exit from the while(){} loop caused by said
loop's 

condition becoming FALSE; however, the else {} would be skipped over if
the loop 

exits unnaturally -- a la through a break statement or because of an
exception.



It is to die for on a semi-daily basis for me (in python)... but I'm not
sure 

this is what the developers above (and their examples) have in mind or
not.



Either implementation would prove useful to me.


[2008-04-09 07:51:11] ois at oisnot dot com

try {

  foreach ($nullValue as $nothing) {

echo 'valid input';

  } else {

//suppress notice

echo 'null value';

  }

  //or/and

} catch (ExceptionObjectNotIterator $e) {

  //object doesnt implement Iterator

  echo $e->getMessage();

}


[2003-11-29 08:59:16] elmi...@php.net

Yes, you're right, my code was wrong. Next try:



$found = false;

while ($row = mysql_fetch_assoc($result)) {

   $found = true;

   print 'Here is a result';

   ...

} 



if (!$found) {

   print 'No results found';

}





The proposed while/else syntax is indeed a bit more elegant.




[2003-11-26 17:21:53] he...@php.net

Read again. Your code would always print 'No results found' while the
intended change wouldn't.


[2003-11-25 19:16:51] elmi...@php.net

Can you give a better example to support your request? Your example can
easily be written as:



while ($row = mysql_fetch_assoc($result)) {

   print 'Here is a result';

   ...

} 



if (!row) {

   print 'No results found';

}



I don't think that this one test is so expensive that it makes it worth
the trouble (and cost) to clutter up the language.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

http://bugs.php.net/bug.php?id=26411


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=26411&edit=1


Req #26411 [Com]: while {} else {}

2010-12-19 Thread trefighter2334 at aol dot com
Edit report at http://bugs.php.net/bug.php?id=26411&edit=1

 ID: 26411
 Comment by: trefighter2334 at aol dot com
 Reported by:php at bellytime dot com
 Summary:while {} else {}
 Status: Open
 Type:   Feature/Change Request
 Package:Scripting Engine problem
 Operating System:   *
 PHP Version:*
 Block user comment: N
 Private report: N

 New Comment:

I'd love to see something like Python's while/else logic implemented in
PHP.



This logical construct would allow developers to define blocks of code
in else 

{} that'd run upon a natural exit from the while(){} loop caused by said
loop's 

condition becoming FALSE; however, the else {} would be skipped over if
the loop 

exits unnaturally -- a la through a break statement or because of an
exception.



It is to die for on a semi-daily basis for me (in python)... but I'm not
sure 

this is what the developers above (and their examples) have in mind or
not.



Either implementation would prove useful to me.


Previous Comments:

[2008-04-09 07:51:11] ois at oisnot dot com

try {

  foreach ($nullValue as $nothing) {

echo 'valid input';

  } else {

//suppress notice

echo 'null value';

  }

  //or/and

} catch (ExceptionObjectNotIterator $e) {

  //object doesnt implement Iterator

  echo $e->getMessage();

}


[2003-11-29 08:59:16] elmi...@php.net

Yes, you're right, my code was wrong. Next try:



$found = false;

while ($row = mysql_fetch_assoc($result)) {

   $found = true;

   print 'Here is a result';

   ...

} 



if (!$found) {

   print 'No results found';

}





The proposed while/else syntax is indeed a bit more elegant.




[2003-11-26 17:21:53] he...@php.net

Read again. Your code would always print 'No results found' while the
intended change wouldn't.


[2003-11-25 19:16:51] elmi...@php.net

Can you give a better example to support your request? Your example can
easily be written as:



while ($row = mysql_fetch_assoc($result)) {

   print 'Here is a result';

   ...

} 



if (!row) {

   print 'No results found';

}



I don't think that this one test is so expensive that it makes it worth
the trouble (and cost) to clutter up the language.


[2003-11-25 12:28:30] php at bellytime dot com

Description:

How about a while...else structure. Often we do 



if (!mysql_num_rows($result)) {

   print 'No results found';

}

while ($row = mysql_fetch_assoc($result)) {

   print 'Here is a result';

   ...

}



Wouldn't it be nicer to do a 



while ($row = mysql_fetch_assoc($result)) {

   print 'Here is a result';

   ...

} else {

   print 'No results found';

}









-- 
Edit this bug report at http://bugs.php.net/bug.php?id=26411&edit=1