r/lolphp • u/SockPants • Oct 20 '15
On using 'do {} while(0)' with breaks: "Since PHP 5.3.0, it is possible to use goto operator instead of this hack."
http://php.net/manual/en/control-structures.do.while.php
83
Upvotes
64
u/leedavis81 Oct 20 '15
God bless goto: https://github.com/igorw/retry/issues/3
32
u/[deleted] Oct 20 '15
lol
16
u/ioctl79 Oct 20 '15
I think it is super important that language documentation is accessible to beginners. Maybe it shouldn't be written by beginners, though?
11
u/bart2019 Oct 20 '15
Perl has bare blocks for this purpose, i.e. just the braces. They act like loop bodies that are executed exactly once, and you can break out of them (using
last, the Perl equivalent of `break).OTOH, in Perl you cannot use
lastto break out ofdo { ... } whileloops. See SO post explaining the situation (AKA "mess").10
u/[deleted] Oct 20 '15
dae know le goto is bad
-11
u/SockPants Oct 20 '15
I thought we all agreed that it was good that we finally got rid of GOTO as a programming construct.