学习scala中的for使用

18 阅读1分钟
object test {
  def main(args: Array[String]):Unit ={
   // for(j  <- 1 to 20){
     // println(j)
    //2.循环守卫
   // for (j<-1 to 20;if(j%2==0);if(j%3==0)){
     // println(j)

    //打印1-20的偶数
   // for(j<-1 to 20){
     // if(j%2==0)
       // println(j)
    //}

    //3.步长
    //1 2 3 4 5 6 7 8(步长:1)
    //1 3 5 7 9 11 13 15(步长:2)
    for(i<-1 to 20 by 2){
      println(i)
    }
  }
}