Groovy中的嵌套"each"循环 [英] Nested `each` loops in Groovy

查看:656
本文介绍了Groovy中的嵌套"each"循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在groovy中需要有关嵌套循环语法的指南.如何在此处使用迭代器打印(a.name的值,b.name的值)的值?

Need guidance on the syntax of nested looping in groovy. How to use iterator to print values of (value of a.name, value of b.name) here?

List a
a.each {
    print(it.name)
    List b = something
    b.each {
        print(value of a.name, value of b.name)
    }
}

推荐答案

List a
a.each { x ->
    println(x.name)
    List b = something
    b.each { y ->
        println(x.name + y.name)
    }
}

这篇关于Groovy中的嵌套"each"循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆