Using 'Break from Loop' to cancel just subroutine macro

I may be blind, but I didn't find it mentioned anywhere that the Break from Loop action treats a subroutine macro as a loop, i.e. it breaks from (cancels) the subroutine without canceling the macro that executes the subroutine. This is in KM 11.0.2.

According to the wiki article, I'd rather expect this behavior from the Cancel Just This Macro action, but it doesn't seem to treat the subroutine macro as a macro, and instead cancels the executing macro.

The only hint I found in this direction is a statement by @peternlewis , where he says

The Continue Loop, Break From Loop, Retry Loop, refer to the surrounding loop (or currently, surrounding Group, but that is a bug), or failing that, to the macro as a whole.

But it's not very clear here that the "macro as a whole" can also be the subroutine without the executing macro.

This behavior of Break from Loop is quite useful, so I hope it's not a bug like the "Group treated as loop" was.

__cancel just subroutine test Macros.kmmacros (4.9 KB)

Interesting.

Since a subroutine is a macro then I'd interpret "macro as a whole" to refer to the subroutine and not its caller.

But we don't really want to rely on interpretations...

Personally I never use the break from loop action unless I actually have a loop to break from :wink:

1 Like

Me too, normally. I found this by trial and error while I was looking for an "early return" from the sub, to save one If…Then nesting level.

Using the Return from Subroutine action would make more sense.

2 Likes

Return from Subroutine action would make more sense.

Oh, that action must have sneaked in recently :wink:

(Actually, I didn't look any further when I found out that Break from Loop does exactly what I need… But this one has the bonus of returning a value when needed, so I'll take it :blush:. Thanks for the hint!)

Funny enough, I have been using the subroutine macro with the Cancel Just This Macro action for years, apparently never thoroughly tested and always believing it would just cancel the subroutine, and yesterday the conditional kicked in for the first time ever…

1 Like