scala 循环

2022年4月18日21:05:44 发表评论 494 views
object test1 {
  def main(args: Array[String]): Unit = {

    val s1 = List("DDD","99990","Shall")
    println("8"*88+"第一种")
    for (elem <- s1) {println(elem)}
    println("8"*88+"第二种")
    for (elem <- s1) {
      if(elem.length>3)
        println(elem)
    }
    println("8"*88+"第三种")

    var s2 =
    for {elem <- s1
      if(elem.length>3)
        st = elem.toUpperCase()
    }yield(st)
    for (elem <- s2) {println(elem)}

    println("8"*88+"第四种")
    var i = 0
    while(i<s2.length){
      println(s2(i))
      i+=2
    }
    for (x <- 1 until 20)println(x)
  }
}

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: