Logic: AND, OR, NOT · 逻辑:AND、OR 与 NOT
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
A club that checks both ends of the age
- A club takes members only from 11 to 16. One test cannot say both ends.
ANDisTRUEonly when both tests areTRUE:Age >= 11 AND Age <= 16.NOTflips a Boolean. The tasks use it on a flag, not on a number.
中文
社团要核对年龄的两端
- 社团只收 11 到 16 岁。一个判断说不了两端。
- 只有两个判断都为
TRUE时,AND才为TRUE:Age >= 11 AND Age <= 16。 NOT把布尔值反过来。练习里把它用在一个标志上,而不是用在一个数字上。
DECLARE Age : INTEGER
Age ← 14
IF Age >= 11 AND Age <= 16 THEN
OUTPUT "accepted"
ELSE
OUTPUT "no"
ENDIF
English
A fare that depends on either age
- A bus fare is free under 5, or at 65 and over. One of those tests is enough.
ORisTRUEwhen either operand isTRUE.
中文
票价取决于两个年龄中的一个
- 不满 5 岁,或年满 65 岁,车票免费。两个判断有一个成立就够了。
- 任一运算数为
TRUE时,OR为TRUE。
DECLARE Age : INTEGER
Age ← 70
IF Age < 5 OR Age >= 65 THEN
OUTPUT "free"
ELSE
OUTPUT "pay"
ENDIF
English
Nest the second decision
- 80 or more is a distinction. Otherwise, 50 or more is a pass, and the rest is a fail.
- The second
IFis the statement underELSE, with its ownENDIF. THENstays on theIFline, including the inner one.
中文
把第二个判断嵌进去
- 80 分及以上是优秀。否则,50 分及以上是及格,剩下的是不及格。
- 第二个
IF是ELSE下面的那条语句,有自己的ENDIF。 THEN留在IF那一行,内层也一样。
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 80 THEN
OUTPUT "Distinction"
ELSE
IF Mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF
English
Watch out
- Write the variable on both sides of
AND.Mark >= 0 AND <= 100is not a test. - IGCSE 0478 puts
THENon the following line. Do not mix the two papers.
中文
注意
AND的两边都要写上变量。Mark >= 0 AND <= 100不是一个判断。- IGCSE 0478 把
THEN放在下一行。两份试卷不要混用。
English
Common mistakes
ELSEbelongs to theIFabove it. Indent the innerIFso the finalENDIFis the outer one.NOTapplies to a Boolean.NOT Markis not how you test a number.
中文
常见错误
ELSE属于它上面的那个IF。把内层IF缩进,最后一个ENDIF才是外层的。NOT作用在布尔值上。NOT Mark不是判断一个数字的写法。
English
Now you try
- One task is an
OR, one is aNOT, and one is the nested grade.
中文
现在你来试
- 一题是
OR,一题是NOT,一题是嵌套的等级。
Read an INTEGER Age. Output free when Age is under 5 or at least 65, using OR. Otherwise output pay. · 读入一个 INTEGER Age。用 OR 判断 Age 是否小于 5 或不小于 65。是则输出 free,否则输出 pay。
Click Run to see the output here. · 点击“运行”查看此处输出。
Alarm is a BOOLEAN set to FALSE. If NOT Alarm, output quiet, otherwise output ring. · Alarm 是 BOOLEAN,设为 FALSE。若 NOT Alarm,输出 quiet,否则输出 ring。
Click Run to see the output here. · 点击“运行”查看此处输出。
Read an INTEGER Mark. Output Distinction for 80 or more, otherwise Pass for 50 or more, otherwise Fail. Put the second IF under · 位于 ELSE, with THEN on the IF line. · 读入一个 INTEGER Mark。80 及以上输出 Distinction,否则 50 及以上输出 Pass,否则输出 Fail。把第二个 IF 放在 ELSE 下面,THEN 留在 IF 那一行。
Click Run to see the output here. · 点击“运行”查看此处输出。