Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
fun main() {
val n = 5
val label = if (n > 3) {
println("big")
"B"
} else {
"S"
}
println(label)
}big B
- Expecting only
B: anifused as a value still runs every line of the chosen block, soprintln("big")prints before"B"becomes the value. - Expecting both blocks to run: only the block whose condition is true runs, and its last expression, here
"B", becomes the value of theif.
- What does the program print when
nis2? - What happens if the
elsebranch is removed?