Variables and DECLARE · 变量与 DECLARE
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 variable stores one value
- A variable has a name and holds one value you can change.
- The 2026 guide writes names in mixed case, starting with a letter:
NumberOfPlayersornumberOfPlayers. - These lessons use a capital first letter, the same shape as the guide's own examples.
中文
变量保存一个值
- 变量有名字,并保存一个可以改变的值。
- 2026 指南用混合大小写的名字,并且以字母开头:
NumberOfPlayers或numberOfPlayers。 - 本课程的例子首字母大写,和指南自己的例子一样。
DECLARE Counter : INTEGER
Counter ← 0
Counter ← Counter + 1
OUTPUT Counter
English
DECLARE, then the arrow
DECLARE Counter : INTEGERcreates the variable and names its type.- The assignment operator is
←. It stores the value on the right. =is not how you store a value.=means "is equal to" inside a test.
中文
先 DECLARE,再用箭头
DECLARE Counter : INTEGER创建变量并写出它的类型。- 赋值运算符是
←。它把右边的值存进去。 =不是用来存值的。=在判断里表示“等于”。
DECLARE Score : INTEGER
Score ← 40
Score ← Score + 2
OUTPUT Score
English
Watch out
- Declare a variable before you use it.
- An identifier starts with a letter. Digits may follow. The guide also allows
_.
中文
注意
- 先声明变量,再使用它。
- 标识符以字母开头,后面可以有数字。指南也允许
_。
English
Common mistakes
Counter ← 1stores 1.Counter = 1is not an assignment.- One variable holds one value. Assigning again replaces it.
中文
常见错误
Counter ← 1存入 1。Counter = 1不是赋值。- 一个变量只保存一个值。再次赋值会替换它。
English
Now you try
- Declare an integer, store a value with
←, and output it.
中文
现在你来试
- 声明一个整数,用
←存入一个值,然后输出它。
Declare Total as an INTEGER, store 8, and output it. · 把 Total 声明为 INTEGER,存入 8,并输出它。
Click Run to see the output here. · 点击“运行”查看此处输出。
Declare Counter as an INTEGER. Start it at 0, add 1, and output it. · 把 Counter 声明为 INTEGER。从 0 开始,加上 1,并输出它。
Click Run to see the output here. · 点击“运行”查看此处输出。