Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
Scala /
for loop
Print numbers from 1 to 10: for (i <- 1 to 10) println(i) // 1, ..., 10 If you use "until", the upper bound is excluded: for (i <- 1 until 10) println(i) // 1, ..., 9 for can traverse lots of things. If you go through a string, you access it char by char: for (c <- "scala") print(c + " ") // s c a l a Go throught the indices of a string and access the a char by index: val s = "scala" for (i <- s.indices) print(s(i) + " ") // s c a l a // s.indices gives Range(0, 1, 2, 3, 4) |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |