is it possible to break out of closure in groovy

后端 未结 9 1929
醉梦人生
醉梦人生 2020-12-09 08:33

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 
}
<         


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 09:02

    Take a look at Best pattern for simulating continue in groovy closure for an extensive discussion.

提交回复
热议问题