dgaramond2 has asked for the wisdom of the Perl Monks concerning the following question:
Why doesn't this work?
$ perl -le'do { print $i++; last if $i>5 } while 1; print "end"'
0
1
2
3
4
5
Can't "last" outside a loop block at -e line 1.
while (no pun intended) this works:
$ perl -le'while (1) { print $i++; last if $i>5 } print "end"'
0
1
2
3
4
5
end
Isn't do {} while as much a loop as while () {}?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: last in do vs last in while/for
by bellaire (Hermit) on Mar 04, 2009 at 18:24 UTC | |
by zwon (Abbot) on Mar 04, 2009 at 19:48 UTC | |
by ikegami (Patriarch) on Mar 04, 2009 at 20:01 UTC | |
|
Re: last in do vs last in while/for
by runrig (Abbot) on Mar 04, 2009 at 17:28 UTC | |
|
Re: last in do vs last in while/for
by baxy77bax (Deacon) on Mar 04, 2009 at 18:22 UTC | |
by ikegami (Patriarch) on Mar 04, 2009 at 19:34 UTC | |
|
Re: last in do vs last in while/for
by locked_user sundialsvc4 (Abbot) on Mar 04, 2009 at 22:31 UTC |