📚 4 Common Facilities of Procedural Languages | 过程式语言的四种常见设施
Procedural languages are built around step-by-step instructions that change a program’s state. They offer a set of common facilities that make it possible to store data, make decisions, repeat actions, and organise code into manageable parts. This article explains four of the most important facilities every Cambridge learner needs to master: variables and assignment, selection, iteration, and subprograms.
过程式语言围绕逐步执行、改变程序状态的指令构建。它们提供了一组常见设施,使存储数据、做出决策、重复操作以及将代码组织为易于管理的部分成为可能。本文讲解剑桥学习者必须掌握的四种最重要设施:变量与赋值、选择、迭代和子程序。
1. What Is a Procedural Language? | 什么是过程式语言?
A procedural language follows the imperative programming paradigm. A program is written as a sequence of instructions that the computer carries out in order, one after another. Each instruction may change the value of a variable, read input, produce output, or alter the flow of control.
过程式语言遵循命令式编程范式。程序被写成一个指令序列,计算机按顺序逐条执行。每条指令可以更改变量的值、读取输入、产生输出或改变控制流程。
Common examples include Pascal, C, BASIC, and Python used in a procedural style. These languages provide built-in facilities that support structured programming, making code easier to write, read, and debug.
常见例子包括 Pascal、C、BASIC 以及以过程式风格使用的 Python。这些语言提供了支持结构化编程的内置设施,使代码更易于编写、阅读和调试。
In a procedural program, the main focus is on actions and the order in which they happen. This makes the flow of execution clear and predictable, which is a key reason why procedural languages remain widely used in education and industry.
在过程式程序中,主要关注点是动作及其发生的顺序。这使得执行流程清晰且可预测,这也是过程式语言至今在教育和工业中广泛使用的关键原因。
2. Facility 1: Variables and Assignment | 设施一:变量与赋值
A variable is a named storage location in memory that holds a value. The assignment statement gives a variable a new value. For example, in pseudocode, score ← 0 stores the value 0 in the variable called score. Assignment is fundamental because it allows a program to remember and update data as it runs.
变量是内存中具有名称的存储位置,用于保存值。赋值语句给变量赋予新值。例如,在伪代码中,score ← 0 将值 0 存入名为 score 的变量。赋值是基础,因为它允许程序在运行时记住并更新数据。
Variables have data types that define what kind of values they can store. The most common types are integer, real, character, Boolean, and string. Choosing the correct data type is important for efficient memory use and for preventing errors such as trying to store text in a numeric variable.
变量具有数据类型,定义它们可以存储哪种值。最常见的类型包括整数、实数、字符、布尔值和字符串。选择正确的数据类型对于高效使用内存以及防止错误(例如尝试将文本存储到数值变量中)非常重要。
| Data type | Typical use |
|---|---|
| Integer | Whole numbers, e.g. 42 |
| Real | Numbers with decimal parts, e.g. 3.14 |
| Character | A single symbol, e.g. ‘A’ |
| Boolean | TRUE or FALSE |
| String | A sequence of characters, e.g. “Hello” |
Without variables and assignment, a program would have no way to remember intermediate results or interact meaningfully with input data. Exams often ask learners to trace the value of a variable after a series of assignments, so careful reading of assignment direction is essential.
没有变量和赋值,程序就无法记住中间结果,也无法有意义地与输入数据交互。考试经常要求学习者在一系列赋值之后追踪变量的值,因此仔细阅读赋值方向至关重要。
3. Facility 2: Selection – Making Decisions | 设施二:选择——做出决策
Selection allows a program to choose between different execution paths based on a condition. The most common form is the IF…THEN…ELSE statement, but many languages also provide a CASE or switch statement for multi-way decisions. Selection is essential because it lets a program respond differently to different inputs or states.
选择结构允许程序根据条件在不同执行路径之间做出选择。最常见的形式是 IF…THEN…ELSE 语句,但许多语言也提供 CASE 或 switch 语句用于多分支决策。选择结构必不可少,因为它使程序能够对不同的输入或状态做出不同响应。
A simple selection in pseudocode looks like this:
伪代码中的简单选择结构如下:
IF score >= 50 THEN
OUTPUT “Pass”
ELSE
OUTPUT “Fail”
ENDIF
Conditions are built from comparison operators such as =, <>, <, >, <=, and >=. They may also be combined using logical operators like AND, OR, and NOT to form more complex Boolean expressions.
条件由比较运算符构建,例如 =、<>、<、>、<= 和 >=。它们也可以使用 AND、OR 和 NOT 等逻辑运算符组合,形成更复杂的布尔表达式。
Nested IF statements allow one decision to be made inside another. A CASE statement is cleaner when there are many possible values to check, such as matching a menu option to a
Published by TutorHao | 体育 Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导