in reply to Can a while loop be stopped with "last"?

As others said, the answer is yes. However this reminds me something interesting. do {} is not a loop structure.

use warnings; use strict; my $i; do { print ++$i; last if ($i == 10); } until (0);

When kyou run this code, it complaints that "Can't "last" outside a loop block at a.pl line 7.". However it still gives what you want, and prints the result "12345678910".

Replies are listed 'Best First'.
Re^2: Can a while loop be stopped with "last"?
by ysth (Canon) on Jul 14, 2004 at 03:33 UTC
    You can correct that somewhat with extra curlies:  do {{ ... }} until/while ... to get next and redo to work, or  { do { ... } until/while ... } to get last to work. Unfortunately, you can't do both (without resorting to a label).