is there a way to \'break\' out of a groovy closure.
maybe something like this:
[1, 2, 3].each { println(it) if (it == 2) break } <
[1, 2, 3].each { println(it) if (it == 2) break }
You can throw an exception:
try { [1, 2, 3].each { println(it) if (it == 2) throw new Exception("return from closure") } } catch (Exception e) { }
Use could also use "findAll" or "grep" to filter out your list and then use "each".
[1, 2, 3].findAll{ it < 3 }.each{ println it }