“Wie Schleife in Scala” Code-Antworten

Wie Schleife in Scala

for (i <- 1 to 3) println(i)
Inquisitive Impala

Wie Schleife in Scala

for {
    i <- 1 to 10
    if i < 4
} println(i)
Inquisitive Impala

Wie Schleife in Scala

for (i <- 1 to 10 if i < 4) println(i)
Inquisitive Impala

Wie Schleife in Scala

val nameMap = Map("firstName" -> "Ed", "lastName" -> "Chigliak")
for ((k,v) <- nameMap) {
    println(s"key: $k, value: $v")
}

val result = for ((k,v) <- nameMap) yield {
    s"key: $k, value: $v"
}
println(result)
Inquisitive Impala

Wie Schleife in Scala

ratings.foreach {
    case(movie, rating) => println(s"key: $movie, value: $rating")
}

ratings.foreach(x => println(s"key: ${x._1}, value: ${x._2}"))
ratings.keys.foreach((movie) => println(movie))
ratings.keys.foreach(println)
ratings.values.foreach((rating) => println(rating))
Inquisitive Impala

Wie Schleife in Scala

for {
    i <- 1 to 10
    if i > 3
    if i < 6
    if i % 2 == 0
} println(i)
Inquisitive Impala

Wie Schleife in Scala

val lengths = for (e <- names) yield {
    // imagine that this required multiple lines of code
    e.length
}
Inquisitive Impala

Wie Schleife in Scala

val names = Seq("chris", "ed", "maurice")
val nums = Seq(1, 2, 3)
Inquisitive Impala

Wie Schleife in Scala

for (i <- 0 until names.length) {
    println(s"$i is ${names(i)}")
}
Inquisitive Impala

Wie Schleife in Scala

names.zipWithIndex.foreach { d =>
    println(s"${d._2} is ${d._1}")
}
Inquisitive Impala

Ähnliche Antworten wie “Wie Schleife in Scala”

Fragen ähnlich wie “Wie Schleife in Scala”

Weitere verwandte Antworten zu “Wie Schleife in Scala” auf Scala

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen