Elegant way for do … while in groovy

前端 未结 6 848
Happy的楠姐
Happy的楠姐 2020-12-29 00:44

How to do code something like this in groovy?

do {

  x.doIt()

} while (!x.isFinished())

Because there is no do ... w

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 01:26

    Update Groovy 2.6 has been abandoned to concentrate on 3.0.

    From Groovy 2.6 on, do-while is supported when enabling the new Parrot Parser, from Groovy 3.0 on this is the default. See release notes:

    // classic Java-style do..while loop
    def count = 5
    def fact = 1
    do {
        fact *= count--
    } while(count > 1)
    assert fact == 120
    

提交回复
热议问题