0
相當於我有這樣的代碼片段:使用List.foreach寫的for循環
val ln = List (1, 2, 3)
for (i <- ln){
println(i*2)
}
是否可以寫相同的代碼,但使用List.foreach
方法?
相當於我有這樣的代碼片段:使用List.foreach寫的for循環
val ln = List (1, 2, 3)
for (i <- ln){
println(i*2)
}
是否可以寫相同的代碼,但使用List.foreach
方法?
ln.foreach(i => println(i*2))