Skip to content

Variables and DECLARE

Cambridge Pseudocode Lesson 2 1:48 English narration · English + 中文 subtitles burned in

space play · ←/→ 5s · j/l 10s · f fullscreen · ,/. speed

Chapters

Transcript
A variable is a named store that holds one value. 变量是一个有名字的存储,里面装着一个值。
The arrow is how a value gets in — read it as "store sixteen into Age", and watch it happen: the sixteen goes into the box, and the box keeps it. 箭头就是值进去的方式—— 把它读作"把 16 存进 Age",然后看着它发生: 16 进到盒子里,盒子把它留住。
This is called assignment. 这叫做赋值。
On a keyboard there is no arrow key, so type it as less-than followed by minus, and the runner treats that as the same arrow. 键盘上没有箭头键,所以就打"小于号加减号", 运行器会把它当作同一个箭头。
Good pseudocode declares a variable before using it, and the line has three parts. 规范的伪代码会在使用一个变量之前先声明它,而那一行有三个部分。
DECLARE is the keyword. DECLARE 是关键字。
Count is the name you choose. Count 是你自己选的名字。
And after the colon, INTEGER says what kind of value it may hold. 而冒号后面的 INTEGER 说明它可以装什么类型的值。
The exam expects that shape — name, colon, type — so learn it as one unit. 考卷要求的就是这个形状——名字、冒号、类型—— 所以把它当作一个整体记下来。
Assign again and the old value is replaced. 再次赋值,旧的值就被替换掉。
Now look at the middle line, the one students misread: Total arrow Total plus five. 现在看中间那一行,学生最容易读错的那一行: Total 箭头 Total 加 5。
It is not a claim that Total equals Total plus five, which would be nonsense. 它并不是在说"Total 等于 Total 加 5",那会是胡话。
The right-hand side is worked out first, using the value Total has now, and adds five to it. 右边先被算出来,用的是 Total 现在的值,再加上 5。
That answer, fifteen, is then stored back into the same box. 那个答案 15,然后被存回同一个盒子里。
Four things to take with you. 带走四点。
One: the arrow stores a value into a variable. 第一:箭头把一个值存进一个变量。
Two: on a keyboard you type it as less-than then minus. 第二:在键盘上,你把它打成"小于号加减号"。
Three: DECLARE gives a variable its name and type. 第三:DECLARE 给一个变量它的名字和类型。
Four: the equals sign tests for equality — it never stores, and lesson five is where you will use it. 第四:等号是用来判断相等的——它从不存储, 而第 5 课就是你会用到它的地方。
Now do the three tasks. 现在去做那三道题。

Log in or create account

IGCSE, A-Level & AP