Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
Scala /
ranges
scala> 1 to 10 res85: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) scala> 1 to 10 by 2 res86: scala.collection.immutable.Range = Range(1, 3, 5, 7, 9) scala> 10 to 1 res87: scala.collection.immutable.Range.Inclusive = Range() scala> 10 to 1 by -1 res88: scala.collection.immutable.Range = Range(10, 9, 8, 7, 6, 5, 4, 3, 2, 1) scala> 1 until 10 res89: scala.collection.immutable.Range = Range(1, 2, 3, 4, 5, 6, 7, 8, 9) scala> (1 until 10).reverse res90: scala.collection.immutable.Range = Range(9, 8, 7, 6, 5, 4, 3, 2, 1) Alternatives: scala> Range.inclusive(1, 10) res91: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) scala> Range.inclusive(1, 10, 3) res92: scala.collection.immutable.Range.Inclusive = Range(1, 4, 7, 10) scala> Range.inclusive(10, 1, -2) res93: scala.collection.immutable.Range.Inclusive = Range(10, 8, 6, 4, 2) Print numbers from 10 to 1: scala> for (i <- 10 to 1 by -1) print(i + " ") 10 9 8 7 6 5 4 3 2 1 |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |