$ perl -MO=Concise,-exec -e'while (foo()) { bar() }' 3 <{> enterloop(next->8 last->d redo->4) v $ perl -MO=Concise,-exec -e'bar() while foo()' $ perl -MO=Concise,-exec -e'do { bar() } while foo()' $ perl -MO=Concise,-exec -e'for (foo()) { bar() }' 8 <{> enteriter(next->d last->g redo->9) lK $ perl -MO=Concise,-exec -e'bar() for foo()' 9 <{> enteriter(next->d last->g redo->a) lK
(Output filtered using grep 'enterloop\|enteriter')
bar() while foo() uses a goto instead. It is implemented almost identically to:
LOOP_START: ( bar() ), goto LOOP_START if foo();
do { bar() } while foo() is not readily representable in Perl, but it doesn't use a loop either. The closest I can get is
LOOP_START: do { bar() }; goto LOOP_START unless foo();
But yes, the answer is "Implementation Details". There's no real reason for it not to work except backwards compatibility.
In reply to Re^3: last in do vs last in while/for
by ikegami
in thread last in do vs last in while/for
by dgaramond2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |