06 条件执行
if/else 语句决定执行哪一块代码。
norm
main() {
Integer score = 82
if score >= 90 {
printLine("excellent")
} else if score >= 60 {
printLine("passed")
} else {
printLine("try again")
}
}输出:
text
passed条件必须是 Boolean。分支按顺序检查,第一个为 true 的分支执行,其余跳过。本节用 if 选择动作;后面将学习把 if 本身作为一个值。
动手试试:把 score 依次改为 95 和 40,判断每次执行哪个分支。
详细规则:语言参考。