Re: [PHP-DEV] Steal labelled break and continue from zig?

2023-02-28 Thread Claude Pache



> Le 27 févr. 2023 à 23:36, Karoly Negyesi  a écrit :
> 
> Hello,
> 
> As I was reading https://kristoff.it/blog/zig-multi-sequence-for-loops/ I
> found a very nice trick which in PHP would be:
> 
> foo: while ($i--) {
>  if ($ % 2) break foo;
> }
> 
> What do you think?
> 

Yes, I use sometimes this feature in JavaScript (which allows to “break” any 
labelled block, not just loops).

That said, it is somewhat less needed, since we have `goto` in PHP. But it 
would be nevertheless welcome. (I won’t go as far as deprecating  `break 3;`, 
although I tend to avoid such code.)

> Le 28 févr. 2023 à 08:45, naitsi...@e.mail.de a écrit :
> 
> Unfortunately goto does not have a good image ;-)
> 


The bad reputation of `goto` is  indeed harmful. I heavily use `goto` in PHP 
because I like structured programming. :-)

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



Re: [PHP-DEV] Steal labelled break and continue from zig?

2023-02-27 Thread naitsirch

Am 27-Feb-2023 23:37:29 +0100 schrieb kar...@negyesi.net:
> Hello,
> 
> As I was reading https://kristoff.it/blog/zig-multi-sequence-for-loops/ I
> found a very nice trick which in PHP would be:
> 
> foo: while ($i--) {
> if ($ % 2) break foo;
> }
> 
> What do you think?
> 
> Charlie

It looks interesting. But we already have goto, which could be used in this 
case, too.

while ($i--) {
if ($i % 2) goto foo;
}

foo:

Unfortunately goto does not have a good image ;-)

Best regards
Christian

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



[PHP-DEV] Steal labelled break and continue from zig?

2023-02-27 Thread Karoly Negyesi
Hello,

As I was reading https://kristoff.it/blog/zig-multi-sequence-for-loops/ I
found a very nice trick which in PHP would be:

foo: while ($i--) {
  if ($ % 2) break foo;
}

What do you think?

Charlie