BUG? Group treated as loop

I just spent a while troubleshooting a macro because I didn't expect the "Break From Loop" action to treat a Group as a loop. (I had a Group within a Repeat loop, which produced strange results when I tried to break from the Repeat loop from within a Group.)

I tested it by making this action, which displays the "before" notification but not the "after" notification.

Maybe this is intended behavior! I use Groups purely to for organizational purposes and it was confusing to find out they play a role in the control flow. There's nothing on the wiki page for the Group action to suggest that this can happen.

Hey Gabriel,

If I understand correctly what you're saying what you've described isn't all that weird in my opinion.

Break from Loop will break out of normal actions outside of a group and act like “Cancel This Macro”.

What is weird is how it responds inside of the repeat if you enable the repeat action in my test case.

Test Break From Loop in a Group.kmmacros (4.6 KB)

In my view this should break out of the repeat loop during the first iteration, but it doesn't – the repeat runs 10 times.

Hey @peternlewis – to reiterate Gabriel's question – is this intentional?

This behavior could have its uses, but it's not expected or intuitive. If it's intentional then we need to document it in the wiki.

-Chris

Oh yeah, good findings. So it seems like Break from Loop breaks from the immediate context, whether it's a Repeat loop, a Group, or an entire Macro.

(Not a conditional, though. In the case below KM displays only the "1" notification, not "3"—meaning the Break from Loop cancels the entire macro.)

Yes, sorry about that. Fixed for the next version. Break From Loop, Retry Loop, Continue Loop will not consider a Group to be a loop.

1 Like

What's the simplest way to replicate this functionality? I'd kind of like to have a simple "break from group" without having to set irrelevant loop conditions

I'm sure it's just my lack of imagination but I can't think of a case where you wouldn't be able to use an IF or SWITCH statement to do what I think you're suggesting. Can you give an example of a use case?