Selection: IF
Cambridge Pseudocode Lesson 5 2:04 English narration · English + 中文 subtitles burned in
Chapters
Transcript
Selection is the second control structure, and it is one test with exactly two exits.
选择是第二种控制结构,它是一个测试,恰好有两个出口。
If the test is true, the program takes the TRUE exit and runs the block between THEN and ENDIF.
如果测试为真,程序走 TRUE 那个出口, 运行 THEN 和 ENDIF 之间的那一段。
If it is false, and there is no ELSE, then nothing happens at all — the program steps over the block and carries on below the ENDIF.
如果为假,而又没有 ELSE,那么什么都不会发生—— 程序跨过那一段,从 ENDIF 下面接着往下走。
ELSE gives that second exit something to do.
ELSE 给第二个出口安排了事情做。
Here the mark is forty-one and the test asks for fifty or more, so the test is false — forty-one is not — and the ELSE block runs instead.
这里的分数是 41,而测试要求 50 或更高, 所以测试为假——41 不是——于是 ELSE 那一段代替它运行。
Say this to yourself every time: exactly one of the two blocks runs.
每次都对自己说这句话:两段里恰好有一段会运行。
Never both, and never neither.
绝不会两段都运行,也绝不会一段都不运行。
Six operators do the testing, and five of them are what you would guess.
有六个运算符负责做判断,其中五个就是你会猜到的那样。
The sixth is the one to write on your hand: not-equal is a pair of angle brackets in pseudocode, less-than followed by greater-than — not the exclamation-mark version Python uses.
第六个是要写在手上的那个: 在伪代码里"不等于"是一对尖括号,小于号后面跟大于号—— 不是 Python 用的那个带感叹号的写法。
And remember from lesson two: a single equals sign here is a test, never a store.
再记住第 2 课的一点:这里的单个等号是判断,绝不是存储。
And here is where marks quietly disappear.
而这里就是分数悄悄消失的地方。
Pseudocode has no indentation rule — indentation is for the reader, not the marker — so the words are what close a block.
伪代码没有缩进规则——缩进是给读者看的,不是给判卷人看的—— 所以是那些词在关闭一个代码块。
THEN opens it, and ENDIF closes it again.
THEN 打开它,而 ENDIF 把它关上。
Leave the ENDIF off and the examiner has no way to tell where your IF was meant to stop.
漏掉 ENDIF,判卷人就没有办法知道你的 IF 本来打算在哪里结束。
Four things to take with you.
带走四点。
One: IF THEN runs its block only when the test is TRUE.
第一:IF ... THEN 只在测试为真时运行它那一段。
Two: ELSE gives the FALSE path, and exactly one branch runs.
第二:ELSE 给出为假的那条路,而恰好有一条分支会运行。
Three: compare with a single equals sign, and not-equal is written as angle brackets.
第三:用单个等号做比较,"不等于"写成一对尖括号。
Four: ENDIF closes the block, and it is the mark most often lost.
第四:ENDIF 关闭这一段,而它是最常被丢掉的那一分。
Now do the three tasks.
现在去做那三道题。