Selection: CASE · 选择:CASE
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
CASE OF picks one branch
- A
CASEruns the branch whose value matches the variable. - Branches are tested in order. The first match runs, and the rest are skipped.
OTHERWISEis the branch for every other value. It comes last.
中文
CASE OF 选择一个分支
CASE运行与变量的值相匹配的那一支。- 分支按顺序测试。第一个匹配的运行,其余跳过。
OTHERWISE是其余所有值的分支。它放在最后。
English
中文
DECLARE Move : CHAR
Move ← 'W'
CASE OF Move
'W' : OUTPUT "west"
'E' : OUTPUT "east"
OTHERWISE : OUTPUT "other"
ENDCASE
English
Watch out
- A character value uses single quotes:
'W'. - Each branch is one statement here. A longer branch is easier to read as an
IF.
中文
注意
- 字符值用单引号:
'W'。 - 这里每个分支是一条语句。更长的分支写成
IF更容易读。
English
Common mistakes
- Close the block with
ENDCASE. - Put a colon after the value, and after
OTHERWISE.
中文
常见错误
- 用
ENDCASE结束这一段。 - 值的后面要有冒号,
OTHERWISE后面也要有。
English
Now you try
- Read a character and choose a word with
CASE OF.
中文
现在你来试
- 读入一个字符,用
CASE OF选出一个单词。
Read a CHAR Move. Output west for W, east for E, and other for anything else. · 读入一个 CHAR Move。W 输出 west,E 输出 east,其他输出 other。
Click Run to see the output here. · 点击“运行”查看此处输出。