1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

scalaでfor使った構文色々

Last updated at Posted at 2012-04-25

to を使って1から10まで出力する

for (i <- 1 to 10) {
    println(i)
}

by を使って0, 10, 20 のように10おきに100まで出力する

for (i <- 0 to 100 by 10) {
    println(i)
}

2重ループを使って九九

for (i <-1 to 10; j <- 1 to 10) {
    println(i * j)
}

yieldを使ってすべての要素に処理を行う

val params: Array[String] = Array("test", "test2")
val newParams = for (s <- params) yield {
    "*" + s + "*"
}
for (s <- newParams) {
    println(s)
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?