Programming concepts — data and control structures · 编程概念——数据与控制结构
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| variable/ˈveərɪəbl/ | 变量 | biàn liàng |
| constant/ˈkɒnstənt/ | 常量 | cháng liàng |
| data type/ˈdeɪtə taɪp/ | 数据类型 | shù jù lèi xíng |
| integer/ˈɪntɪdʒə/ | 整数 | zhěng shù |
| real/rɪəl/ | 实数 | shí shù |
| string/strɪŋ/ | 字符串 | zì fú chuàn |
| Boolean/ˈbuːlɪən/ | 布尔值 | bù ěr zhí |
| sequence/ˈsiːkwəns/ | 顺序 | shùn xù |
| selection/sɪˈlekʃn/ | 选择 | xuǎn zé |
| iteration/ˌɪtəˈreɪʃn/ | 迭代 | dié dài |
Programming building blocks
- Programs store data in variables 变量 and constants 常量, each with a data type 数据类型.
- They are built from three control structures.
- We finish with the totalling and counting patterns.
编程构建块
- 程序把数据存储在变量(variables)和常量(constants)中,每个有一个数据类型(data type)。
- 它们由三种控制结构构建。
- 我们以求和和计数模式结束。
Variables, constants and data types
- A variable can change; a constant is fixed. Declare both before use.
- Five basic data types: integer 整数 (whole number), real 实数 (decimal), char (one character), string 字符串 (text), Boolean 布尔值 (
TRUE/FALSE).
The three control structures: sequence 顺序 runs steps in order, selection 选择 chooses a branch, iteration 迭代 repeats a body.
变量、常量和数据类型
- 一个变量能改变;一个常量是固定的。两者都在使用前声明。
- 五种基本数据类型:integer(整数)、real(小数)、char(一个字符)、string(文本)、Boolean(布尔,
TRUE/FALSE)。
DECLARE Score : INTEGER
CONSTANT Pi ← 3.142

三种控制结构:顺序按顺序运行步骤,选择选取一个分支,迭代重复一个主体。
What is the difference between a variable and a constant? · 一个变量和一个常量之间的区别是什么?
A variable's value can change; a constant is set once and never changes. · 一个变量的值能改变;一个常量被设置一次且从不改变。
Match each value to its data type. · 把每个值匹配到它的数据类型。
Whole number = integer; decimal = real; text in quotes = string (a single char like 'A' is char). · 整数 = integer;小数 = real;引号中的文本 = string(像 'A' 这样的单个字符是 char)。
Sequence and selection
- Sequence — steps run one after another, top to bottom.
- Selection — choose which steps run, with
IF…ELSE(orCASEfor many options):
Variables and constants are named stores for values, set in the program's code.
顺序与选择
- 顺序(sequence)——步骤一个接一个运行,从上到下。
- 选择(selection)——选择哪些步骤运行,用
IF…ELSE(或CASE用于许多选项):
IF Score >= 50
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF

变量和常量是值的命名存储,在程序的代码中设置。
How an IF … ELSE IF ladder decides · 一个 IF … ELSE IF 阶梯如何决定
The conditions are tested top to bottom; the FIRST one that is true runs and the rest are skipped. Slide the score and watch which branch lights up. · 条件从上到下被测试;第一个为真的运行,其余的被跳过。滑动分数,看哪个分支亮起。
Which structure chooses which steps to run based on a condition? · 哪种结构根据一个条件选择运行哪些步骤?
Selection branches on a condition; sequence runs in order; iteration repeats. · 选择根据一个条件分支;顺序按顺序运行;迭代重复。
Iteration and totalling
- Count-controlled (
FOR) repeats a fixed number of times. - Pre-condition (
WHILE) tests before — may run zero times. Post-condition (REPEAT…UNTIL) tests after — runs at least once. - Totalling:
Total ← Total + Value; counting:Count ← Count + 1.
While a program runs, its variables are held in the computer's memory (RAM).
迭代与求和
- 计数控制(count-controlled,
FOR)重复一个固定的次数。 - 前置条件(pre-condition,
WHILE)之前测试——可能运行零次。后置条件(post-condition,REPEAT…UNTIL)之后测试——至少运行一次。 - 求和:
Total ← Total + Value;计数:Count ← Count + 1。

程序运行时,它的变量被保存在计算机的内存(RAM)中。
A WHILE loop tests its condition before the body (so it may run zero times), while a REPEAT...UNTIL loop tests after the body (so it always runs at least once). · 一个 WHILE 循环在主体之前测试它的条件(所以它可能运行零次),而一个 REPEAT...UNTIL 循环在主体之后测试(所以它总是至少运行一次)。
Pre-condition (WHILE) can skip entirely; post-condition (REPEAT) always runs once — choose by whether the body must run at least once. · 前置条件(WHILE)能完全跳过;后置条件(REPEAT)总是运行一次——根据主体是否必须至少运行一次来选择。
You've got it
- variable changes, constant is fixed; types: integer, real, char, string, Boolean
- three structures: sequence, selection (IF/CASE), iteration (FOR/WHILE/REPEAT)
- WHILE tests before (0+ times); REPEAT tests after (1+ times)
- totalling = running total; counting = add 1 each time
你掌握了
- 变量改变,常量固定;类型:integer、real、char、string、Boolean
- 三种结构:顺序、选择(IF/CASE)、迭代(FOR/WHILE/REPEAT)
- WHILE 之前测试(0+ 次);REPEAT 之后测试(1+ 次)
- 求和 = 运行总和;计数 = 每次加 1
Which line keeps a running total? · 哪一行保持一个运行总和?
total ← total + value accumulates the sum; count ← count + 1 counts occurrences. · total ← total + value 累积和;count ← count + 1 计数出现次数。