in reply to last in do vs last in while/for

'Isn't do {} while as much a loop as while () {}?'

not exactly. if you are do-whileing then you are evaluating loop after you do something , so technically you are not in the loop, that is how you make sure that something is done (in the 'contents' of a loop) even if a condition is not good to go. and because perl complains ('Can't "last" outside a loop block at -e line 1.') it should be obvious that last is dependent on a loop

hope this helps (please anyone correct if i'm wrong)

Replies are listed 'Best First'.
Re^2: last in do vs last in while/for
by ikegami (Patriarch) on Mar 04, 2009 at 19:34 UTC

    It doesn't matter whether the it's bottom tested or not. For example, you can break out of bottom tested loops in Visual Basic.

    Also, consider

    local $\="\n"; print('a'); { print('b'); last; print('c'); } print('d');
    a b d

    versus

    local $\="\n"; print('a'); do { print('b'); last; print('c'); }; print('d');
    a b Can't "last" outside a loop block at a.pl line 5.

    See bellaire's post for the real reason.