in reply to Re^2: next'ing out of a "foreach" loop within a subroutine
in thread next'ing out of a "foreach" loop within a subroutine

"So the "last" ends the foreach loop since a subroutine returns by default the result of the last operation right?"

The result of the last operation is not the last operation, right? So this does not provide an answer.

If the last statement comes without a LABEL, it ends the innermost enclosing loop. Semantically, a sub is a block, and in the demo code, the innermost enclosing loop is that foreach loop.

It is just the way the language was designed. You can argue that this should never happen, and the last statement inside a sub should not impact any loop outside the sub.

  • Comment on Re^3: next'ing out of a "foreach" loop within a subroutine