Groovy - how to exit each loop?

前端 未结 4 1647
粉色の甜心
粉色の甜心 2021-02-03 21:39

I\'m new to Grails/Groovy and am trying to find a node in a an xml file; I\'ve figured out how to iterate over all of them, but I want to exit the loop when the target node is f

4条回答
  •  长发绾君心
    2021-02-03 22:14

    I think this should work too, stopping at the first match.

    def result = records.children().find { domain -> 
        if (domain.@domain_name == targetDomain) {
            // Do stuff
            ...
            return true
        } else {
            return false
        }
    }
    

提交回复
热议问题