Hi Fred, I think you have discovered a potential short-coming in the compiler. The intention is to mostly follow Java behavior.
A "break someLabel" statement should break out of an enclosed statement having label "someLabel" (A) or the current for/while/do/switch if no label is given (B). If an unknown label is given, there should be a compile error (C). Currently, if the label is known but not in the "Java correct" scope, we are getting (B) instead of (C). So, it's not actually doing a GOTO "exit" in your example but is exiting the "for". int i = 5 for (int j=0; j<2; j++) { break exit } i += 10 exit: i += 100 assert i == 115 However, "continue exit" is actually doing a goto to "exit". The code was written before my time, I'll have to dive in further to work out if this is a feature or bug. The code does seem to be giving more flexibility than what Java would do. It is probably worth creating an issue so that we can follow through whether we have the correct behavior. I'd recommend in the meantime following Java style, that should give the behavior Java folks would expect with the current implementation and would not change if we removed the current extra flexibility. Cheers, Paul. On Tue, Feb 1, 2022 at 7:55 AM Fred Eisele <fredrick.eis...@gmail.com> wrote: > > I am seeing some inconsistency in the documentation for use of breaking to > labels. > > This indicates that groovy works similar to fortran, goto label. > https://groovy-lang.org/semantics.html#_labeled_statements > > for (int j=0;j<i;j++) { > println "j=$j" > if (j == 5) { break exit } > } > exit: println "i=$i" > > > In other places it sounds more like java. > https://stackoverflow.com/questions/6126702/java-groovy-double-for-statement-question > > outerLoop: > for (...) { > for (...) { > if (...) { > break outerLoop; > } > } > }