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
Am 27-Feb-2023 23:37:29 +0100 schrieb karoly@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
Le 27 févr. 2023 à 23:36, Karoly Negyesi karoly@negyesi.net 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, naitsirch@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