Sunday, 14 June 2009

Funky stuff with for loops & prepopulating lists

You can pre populate a list with a loop like "val list = 1 to 20"

You can return stuff from a for loop with the "yield" command

def looping() = {
val myList = (1 to 20 by 3)
println(myList)

val list2 = for( i <- myList if i % 2 == 0 ) yield i
println(list2)
}

No comments:

Post a comment