Scala 範例 - 迴圈丟出 (forYields)

原始程式:forYields.scala

/** Turn command line arguments to uppercase */
object forYields {
  def main(args: Array[String]) {
    val res = for (a <- args) yield a.toUpperCase
    println("Arguments: " + res.toString)
  }
}

執行結果:

D:\Scala\code>scalac forYields.scala

D:\Scala\code>scala forYields
Arguments: Array()

D:\Scala\code>scala forYields 1 5 2 3 7
Arguments: Array(1, 5, 2, 3, 7)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License