📚 Programming Concepts | 编程概念
In the IGCSE Cambridge Science syllabus, programming concepts form the foundation of computational thinking. This article covers the essential ideas you need to understand and apply in exams, from algorithms to debugging.
在剑桥 IGCSE 科学考纲中,编程概念是计算思维的基础。本文将涵盖你在考试中需要理解和应用的核心知识点,从算法到调试。
1. Algorithms and Programs | 算法与程序
An algorithm is a step-by-step set of instructions used to solve a problem or perform a task. A program is an algorithm written in a language that a computer can understand and execute.
算法是用于解决问题或执行任务的分步指令集合。程序是用计算机能理解并执行的语言编写的算法。
Algorithms can be expressed in many ways, including pseudocode, flowcharts and structured English. In the IGCSE exam, you may be asked to write or interpret pseudocode.
算法可以用多种方式表达,包括伪代码、流程图和结构化英语。在 IGCSE 考试中,你可能会被要求编写或解释伪代码。
Key features of a good algorithm are clarity, finiteness (it must end) and effectiveness (each step must be unambiguous and doable).
一个好的算法的关键特征是清晰性、有限性(必须能结束)和有效性(每一步必须无歧义且可行)。
2. Programming Languages | 编程语言
Programming languages are classified into low-level and high-level languages. Low-level languages such as machine code and assembly language are closer to the hardware; high-level languages such as Python and Java are closer to human English-like syntax.
编程语言分为低级语言和高级语言。低级语言(如机器码和汇编语言)更接近硬件;高级语言(如 Python 和 Java)更接近人类英语类语法。
High-level languages are easier to learn, write and debug, and are portable across different machines. Low-level languages run fast and directly control hardware but are difficult for humans.
高级语言更易于学习、编写和调试,并且可跨不同机器移植。低级语言运行速度快、可直接控制硬件,但对人而言很难。
For IGCSE, you should be able to compare these levels and give examples: machine code (binary 0s and 1s), assembly (mnemonics like LOAD, ADD), high-level (Python, Java, Visual Basic).
对于 IGCSE,你应能比较这些层次并举例:机器码(二进制 0 和 1)、汇编(助记符如 LOAD、ADD)、高级语言(Python、Java、Visual Basic)。
3. Variables and Constants | 变量与常量
A variable is a named memory location whose value can change during program execution. A constant is a named memory location whose value never changes.
变量是程序执行期间值可以改变的命名存储单元。常量是其值永不改变的命名存储单元。
Example: in the statement score ← score + 1, ‘score’ is a variable holding a changing total, while ‘PI = 3.142’ is a constant.
例如:在语句 score ← score + 1 中,’score’ 是保存不断变化总数的变量,而 ‘PI = 3.142’ 是常量。
Good practice: use meaningful names (e.g., totalMarks, not x) and declare variables clearly at the start of a program.
良好实践:使用有意义的名称(例如 totalMarks,而不是 x),并在程序开头清晰地声明变量。
4. Data Types | 数据类型
The main data types are: integer (whole numbers), real/float (decimal numbers), char (single character), string (text), Boolean (True/False), and sometimes date/time.
主要数据类型包括:整型(整数)、实型/浮点型(小数)、字符型(单个字符)、字符串(文本)、布尔型(True/False),有时还有日期/时间。
Choosing the correct data type is important for efficient memory use and correct operations. For example, you cannot multiply two strings.
选择正确的数据类型对于高效使用内存和正确运算很重要。例如,不能将两个字符串相乘。
Exam tip: write data types in capital letters (INTEGER, REAL, CHAR, STRING, BOOLEAN) when writing pseudocode.
考试提示:在编写伪代码时,数据类型用大写字母(INTEGER、REAL、CHAR、STRING、BOOLEAN)。
5. Sequence | 顺序结构
Sequence is the default control structure: statements execute one after another, from top to bottom, in the order they are written.
顺序是默认的控制结构:语句按编写顺序自上而下逐条执行。
Example pseudocode:
例如伪代码:
INPUT num1
INPUT num2
total ← num1 + num2
OUTPUT total
The order matters: swapping the two INPUT statements would exchange the values entered, which may change the output.
顺序很重要:交换两个 INPUT 语句会交换输入的值,这可能会改变输出。
6. Selection | 选择结构
Selection allows a program to choose different paths based on conditions. The standard structures are IF…THEN…ELSE and CASE.
选择结构允许程序根据条件选择不同路径。标准结构是 IF…THEN…ELSE 和 CASE。
IF…THEN…ELSE syntax:
IF…THEN…ELSE 语法:
IF condition THEN
statements A
ELSE
statements B
ENDIF
Example: IF age ≥ 18 THEN OUTPUT “Adult” ELSE OUTPUT “Minor” ENDIF. Note the use of ≥ for “greater than or equal to”.
例如:IF age ≥ 18 THEN OUTPUT “Adult” ELSE OUTPUT “Minor” ENDIF。注意使用 ≥ 表示“大于或等于”。
Nested selection: an IF inside another IF. Keep nesting shallow for readability, or use IF…ELSE IF…ELSE…ENDIF.
嵌套选择:一个 IF 在另一个 IF 内。为了可读性,应保持嵌套较浅,或使用 IF…ELSE IF…ELSE…ENDIF。
7. Iteration | 循环结构
Iteration (looping) repeats a block of statements. The main types are FOR loop (count-controlled) and WHILE / REPEAT-UNTIL loops (condition-controlled).
循环(迭代)重复执行一段语句。主要类型是 FOR 循环(计数控制)和 WHILE / REPEAT-UNTIL 循环(条件控制)。
FOR loop:
FOR 循环:
FOR i ← 1 TO 10
OUTPUT i
NEXT i
WHILE loop tests before each iteration; REPEAT-UNTIL tests after, so it always runs at least once.
WHILE 循环在每次迭代前测试;REPEAT-UNTIL 在之后测试,所以它至少运行一次。
WHILE example:
WHILE 示例:
WHILE count < 5 DO
OUTPUT count
count ← count + 1
ENDWHILE
Beware of infinite loops: you must ensure the condition eventually becomes False.
谨防死循环:你必须确保条件最终会变为 False。
8. Operators | 运算符
Arithmetic operators: + (add), − (subtract), × or * (multiply), ÷ or / (divide), MOD (remainder), DIV (integer division). IGCSE pseudocode often uses +, −, *, /, MOD, DIV.
算术运算符:+(加)、−(减)、× 或 *(乘)、÷ 或 /(除)、MOD(取余)、DIV(整除)。IGCSE 伪代码常用 +、−、*、/、MOD、DIV。
Example: 17 MOD 5 = 2 and 17 DIV 5 = 3.
例如:17 MOD 5 = 2,17 DIV 5 = 3。
Relational operators: =, ≠, <, >, ≤, ≥. Logical operators: AND, OR, NOT. Example: IF temperature > 30 AND humidity > 60 THEN …
关系运算符:=、≠、<、>、≤、≥。逻辑运算符:AND、OR、NOT。例如:IF temperature > 30 AND humidity > 60 THEN …
Order of operations follows BODMAS/BIDMAS, and in programming you can use brackets to be explicit.
运算顺序遵循 BODMAS/BIDMAS,编程中可以用括号来明确表达。
9. Input, Processing, Output (IPO) | 输入、处理、输出
Most programs follow the IPO model: receive INPUT (e.g., keyboard, sensor), PROCESS (calculate, compare), and OUTPUT (e.g., screen, printer, file).
大多数程序遵循 IPO 模型:接收输入(如键盘、传感器),进行处理(计算、比较),然后输出(如屏幕、打印机、文件)。
Pseudocode keywords: INPUT (or READ) for input, OUTPUT (or PRINT / WRITE) for output.
伪代码关键字:INPUT(或 READ)用于输入,OUTPUT(或 PRINT / WRITE)用于输出。
In exams, always write clear prompts so the user knows what to enter, e.g., OUTPUT “Enter your name:” then INPUT name.
在考试中,输出中要写清晰的提示让用户知道输入什么,例如 OUTPUT “Enter your name:” 然后 INPUT name。
10. Testing and Debugging | 测试与调试
Testing is checking that a program meets its requirements and behaves correctly. Use normal, boundary and erroneous test data.
测试是检查程序是否满足需求并正确运行。应使用正常、边界和错误三类测试数据。
Normal data: typical expected values. Boundary data: values at the edges of a valid range (e.g., 0 and 100 if valid marks are 0–100). Erroneous data: invalid values (e.g., −5 or 150) to check error handling.
正常数据:典型的预期值。边界数据:有效范围边缘的值(例如:若有效分数为 0–100,则取 0 和 100)。错误数据:无效值(如 −5 或 150)用于检查错误处理能力。
Debugging is the process of finding and fixing errors. Common types: syntax errors, logic errors and runtime errors. Trace tables help you follow variables step by step.
调试是发现并修复错误的过程。常见类型:语法错误、逻辑错误和运行时错误。跟踪表帮助你逐步追踪变量的变化。
Published by TutorHao | Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导