043_嵌套循环

image-20210324092619926

package com.atguigu.chapter04.myfor

object MultiFor {
  def main(args: Array[String]): Unit = {
    for(i <- 1 to 3; j <- 1 to 3) {
      println(" i =" + i + " j = " + j) //输出即句 9
    }

    //上面的写法,可以写成这样的形式
    println("==========================")
    for(i <- 1 to 3) {
      for (j <- 1 to 3) {
        println(" i =" + i + " j = " + j) //输出即句 9
      }
    }

  }
}

但是内层循环要是含有一些业务逻辑

你就不好搞了


results matching ""

    No results matching ""