Groovy - for 关键字

Summary

  • 基本循环结构。
  • 传统的for循环结构。
  • 使用 for in 模式的循环结构。

Demo

class Main {
    static void main(args){
        String str = ""

        // 第一种,传统的循环
        for(int i=0; i<5; i++){
            str += "Groovy"
        }


        // 第二种,for in 的遍历循环,可对应多种数据类型。
        ArrayList<String> arrayList = new ArrayList<String>()
        arrayList.addAll(["A","B","C"])
        for (x in arrayList){
            println(x)
        }

    }
}
posted @ 2020-05-28 09:17  duchaoqun  阅读(330)  评论(0编辑  收藏  举报