Scala simple concepts

A simple iteration over Array in Scala can be done as:
  val xs:Array[String] = Array[String]("a", "b", "c", "d", "e")
  for((x,i) <- xs.iterator.zipWithIndex) println(i + "th element is " + x)
  for((x,i) <- xs.view.zipWithIndex) println(i + "th element is " + x) 
  for (i <- xs.indices) println(i + "th element is " + xs(i))
  for (i <- 0 until xs.length) println(i + "th element is " + xs(i))
  for (i <- xs.length - 1 to 0 by -1) println(i + "th element is " + xs(i))

Comments