What Happens?
- Thunks: pass-by-name for explicit nonstrict evaluation of function arguments
- def fcond(b: Boolean, t: => Int, f: => Int) : Int =
- if b then t else f
- for i <- 1 to 10 do
- var x = 0
- var y = 0
- val z = fcond(scala.util.Random.nextInt % 2 == 0,
- {x=1; 111},
- {y=2; 222})
- println(s"x=$x, y=$y, z=$z")