Control Flow
Choice Labels
Choose a label from a few known numeric choices.
Choice Labels
ChoiceLabels.scala
object Main {
def main(args: Array[String]): Unit = {
val code =
var label = "other"
if (code == 1) {
label = "start"
}
if (code == 2) {
label = "middle"
}
println("code=" + code)
println("label=" + label)
}
}
object Main {
def main(args: Array[String]): Unit = {
val code =
var label = "other"
if (code == 1) {
label = "start"
}
if (code == 2) {
label = "middle"
}
println("code=" + code)
println("label=" + label)
}
}
object Main {
def main(args: Array[String]): Unit = {
val code =
var label = "other"
if (code == 1) {
label = "start"
}
if (code == 2) {
label = "middle"
}
println("code=" + code)
println("label=" + label)
}
}
choice-labels
Control flow can map a small code to a readable label. Simple branches keep the choice explicit and traceable.