📚 GCSE Computer Science: Programming Fundamentals | GCSE 计算机:编程基础 考点精讲
Programming fundamentals form the backbone of any GCSE Computer Science course. Mastering these core concepts – from variables and data types to control structures and algorithms – is essential for writing correct, efficient code and for tackling exam questions that test your ability to read, write, and debug programs. In this revision guide, we cover every key topic you need to know, explained clearly with English–Chinese bilingual notes and practical examples.
编程基础是 GCSE 计算机科学的根基。从变量、数据类型到控制结构和算法,掌握这些核心概念对于写出正确高效的代码以及应对考试中考查读、写、调试程序的问题至关重要。本复习指南涵盖你需要了解的每个关键知识点,并配以清晰的中英双语讲解和实用示例。
1. Variables and Constants | 变量与常量
A variable is a named storage location in memory whose value can change while the program runs. Choose meaningful names – for example playerScore rather than x. A constant is similar, but its value is fixed once assigned and cannot be altered during execution. Constants make code more readable and help avoid magic numbers.
变量是内存中一个有名称的存储位置,其值在程序运行期间可以改变。命名应具有可读性——比如用 playerScore 而非 x。常量则类似,但一旦赋值就不能在执行期间修改。常量让代码更易读,并有助于避免魔术数字。
Examples in pseudocode:
伪代码示例:
CONSTANT TAX_RATE = 0.2 score = 0 score = score + 10
In many exam boards, constants are declared with CONST or CONSTANT, and attempting to change a constant is a logic error.
在许多考纲中,常量用 CONST 或 CONSTANT 声明,试图修改常量是一个逻辑错误。
2. Data Types | 数据类型
Every piece of data in a program has a data type, which tells the computer how to interpret and store the value. The five fundamental types you must know are: integer (whole numbers), float/real (numbers with decimal parts), Boolean (TRUE or FALSE), character (a single alphanumeric symbol), and string (a sequence of characters).
程序中的每个数据都有一个数据类型,它告诉计算机如何解释和存储该值。你必须掌握的五种基本类型是:整型(整数)、浮点型/实型(带小数部分的数字)、布尔型(TRUE 或 FALSE)、字符型(单个字母数字符号)和字符串(一组字符序列)。
Type mismatches cause errors – for instance, adding a string to an integer without conversion. Most GCSE languages require explicit type conversion or casting, e.g., int('123') or str(456).
类型不匹配会导致错误——例如在不进行转换的情况下将字符串与整数相加。大多数 GCSE 语言要求显式类型转换或强制转换,例如 int('123') 或 str(456)。
3. Operators | 运算符
Operators perform operations on data. Arithmetic operators include +, -, *, /, MOD (remainder), and DIV (integer division). Comparison operators return Boolean values: == (equal), != or <> (not equal), >, <, >=, <=. Logical operators (AND, OR, NOT) combine Boolean expressions. The order of operations (BODMAS/brackets first) applies, and in Boolean logic, NOT has the highest precedence, then AND, then OR.
运算符对数据执行操作。算术运算符包括 +、-、*、/、MOD(取余)和 DIV(整除)。比较运算符返回布尔值:==(等于)、!= 或 <>(不等于)、>、<、>=、<=。逻辑运算符(AND、OR、NOT)用于组合布尔表达式。运算顺序(BODMAS/括号优先)适用,在布尔逻辑中 NOT 优先级最高,其次是 AND,最后是 OR。
Exam tip: trace expressions carefully – 3 + 5 * 2 equals 13, not 16, because multiplication happens first.
考试提示:仔细求值——3 + 5 * 2 等于 13 而不是 16,因为乘法先执行。
4. Sequence and Structured Programming | 顺序与结构化编程
The most basic control structure is sequence: instructions are executed line by line in the order they appear. Together with selection and iteration, sequence forms the basis of structured programming, which avoids spaghetti code and improves readability. Structured programs use clear indentation, meaningful identifiers, and modular design.
最基本的控制结构是顺序:指令按出现的顺序逐行执行。顺序与选择、循环一起构成了结构化编程的基础,这避免了混乱的意大利面条式代码,并提高了可读性。结构化程序使用清晰的缩进、有意义的标识符和模块化设计。
In pseudocode, sequence looks like:
在伪代码中,顺序结构如下:
total = 0 total = total + price tax = total * 0.2 OUTPUT total
Every step is performed once, top to bottom.
每一步执行一次,从上到下。
5. Selection (if-else) | 选择结构
Selection allows the program to make decisions and execute different code branches based on conditions. The simplest form is IF ... THEN ... ENDIF. For two-way decisions, use IF ... THEN ... ELSE ... ENDIF. For multiple conditions, you can nest IF statements or use `ELSE IF` (or `ELIF`) to keep the code flat and readable.
选择允许程序根据条件做出决策并执行不同的代码分支。最简单的形式是 IF ... THEN ... ENDIF。对于二选一的情况,使用 IF ... THEN ... ELSE ... ENDIF。对于多个条件,可以嵌套 IF 语句或使用 `ELSE IF`(或 `ELIF`)使代码保持扁平易读。
Example:
示例:
IF score >= 90 THEN
grade = 'A'
ELSE IF score >= 75 THEN
grade = 'B'
ELSE
grade = 'C'
ENDIF
Always pay attention to the exact boundaries: using >= versus > changes the logic and can easily lose marks in trace-table questions.
务必注意边界条件:使用 >= 还是 > 会改变逻辑,在跟踪表题目中很容易失分。
6. Iteration (Loops) | 循环结构
Iteration repeats a block of code. GCSE specifications usually require two types: count‑controlled loops (FOR loops) and condition‑controlled loops (WHILE or REPEAT-UNTIL). A FOR loop runs a set number of times, e.g. FOR i = 1 TO 10. A WHILE loop repeats as long as a condition is TRUE, and a REPEAT-UNTIL loop runs at least once before checking the condition.
循环重复执行一段代码。GCSE 考纲通常要求两种类型:计数控制循环(FOR 循环)和条件控制循环(WHILE 或 REPEAT-UNTIL)。FOR 循环运行固定次数,例如 FOR i = 1 TO 10。WHILE 循环在条件为 TRUE 时重复,而 REPEAT-UNTIL 循环至少运行一次再检查条件。
Choosing the right loop matters: use FOR when you know in advance how many iterations are needed; use WHILE when the end depends on a run‑time condition (e.g., user input). Beware of infinite loops – always ensure the condition will eventually become false.
选择合适的循环很重要:当预先知道需要多少次迭代时使用 FOR;当结束依赖于运行时条件(例如用户输入)时使用 WHILE。当心无限循环——始终确保条件最终会变为假。
7. Arrays / Lists | 数组与列表
An array (or list in some languages) stores multiple items of the same data type under a single identifier, accessed by an index. In GCSE, indexing usually starts at 0 or 1 – check the pseudocode rules. Typical operations include creating an array, accessing an element by its index, assigning a value, iterating through the array, and finding its length.
数组(某些语言中叫列表)在单一标识符下存储多个相同数据类型的元素,通过索引访问。在 GCSE 中,索引通常从 0 或 1 开始——注意伪代码规则。典型操作包括创建数组、通过索引访问元素、赋值、遍历数组以及获取其长度。
Example in pseudocode:
伪代码示例:
DECLARE names[5]
names[0] = "Alice"
names[1] = "Bob"
FOR i = 0 TO LEN(names)-1
OUTPUT names[i]
NEXT i
2D arrays are also covered: they are like tables with rows and columns accessed using two indices, e.g. grid[row, col].
二维数组也会涉及:它们类似于表格,用两个索引访问行和列,例如 grid[row, col]。
8. Subroutines and Functions | 子程序与函数
Subroutines (procedures) and functions help break programs into manageable, reusable blocks. A procedure performs a task but does not return a value; a function performs a task and returns a value using a RETURN statement. Both can accept parameters (arguments) passed by value or by reference.
子程序(过程)和函数有助于将程序分解为易于管理、可复用的模块。过程执行任务但不返回值;函数执行任务并通过 RETURN 语句返回值。两者都可以接收按值传递或按引用传递的参数。
Key exam skills: identify the difference between a parameter (formal definition) and an argument (actual value), trace execution when a subroutine is called, and use local variables to avoid side effects.
关键考试技巧:识别参数(形式定义)与实参(实际值)的区别;跟踪子程序调用时的执行过程;使用局部变量避免副作用。
9. Input and Output | 输入与输出
Programs must communicate with the outside world. Input gets data from the user or a file; typical pseudocode keywords are INPUT, READ, or USERINPUT. Output displays or sends data, using OUTPUT or PRINT. Always consider data types: an INPUT usually returns a string, so you need to convert it (e.g., int(INPUT())) if you intend to do arithmetic.
程序必须与外界通信。输入从用户或文件获取数据;典型的伪代码关键字是 INPUT、READ 或 USERINPUT。输出显示或发送数据,使用 OUTPUT 或 PRINT。时刻注意数据类型:INPUT 通常返回字符串,因此如果要进行算术运算就需要转换(例如 int(INPUT()))。
Good practice: always include a prompt so the user knows what to enter. For example, INPUT 'Enter your age: '.
良好做法:始终包含提示信息,让用户知道要输入什么。例如 INPUT 'Enter your age: '。
10. String Manipulation | 字符串处理
String handling techniques appear frequently in GCSE papers. You must be able to use concatenation (joining strings with +), find the length of a string (LEN() or length), extract substrings (SUBSTRING(str, start, length)), and change case or count characters.
字符串处理技巧在 GCSE 试题中经常出现。你必须能够使用拼接(用 + 连接字符串)、获取字符串长度(LEN() 或 length)、提取子串(SUBSTRING(str, start, length))以及改变大小写或统计字符。
Common exam tasks: validate a string’s format (e.g., check if it’s a valid email), encode/decode by shifting characters, or create initials from a full name. Always watch the index: the first character is often at position 0 or 1 depending on the pseudocode convention.
常见考试任务:验证字符串格式(例如检查是否为有效电子邮件)、通过字符移位进行编码/解码,或从全名生成首字母缩写。时刻注意索引:根据伪代码约定,第一个字符通常在位置 0 或 1。
11. Common Algorithms (Searching & Sorting) | 常见算法(搜索与排序)
Two fundamental search algorithms are linear search and binary search. Linear search checks each element one by one; it works on unsorted data but is slow (O(n)). Binary search repeatedly divides a sorted list in half; it is very fast (O(log n)) but requires sorted data. You must be able to trace both algorithms and state their advantages/disadvantages.
两种基本的搜索算法是线性搜索和二分搜索。线性搜索逐个检查每个元素;它适用于未排序数据但速度较慢(O(n))。二分搜索不断将有序列表对半分;速度非常快(O(log n))但需要有序数据。你必须能够跟踪这两种算法并说明其优缺点。
For sorting, the GCSE requirements usually include bubble sort and sometimes merge sort or insertion sort. Bubble sort compares adjacent pairs and swaps them if they are out of order, making multiple passes. Merge sort uses a divide-and-conquer approach: split, sort recursively, merge. You should understand their efficiency and be able to complete partially filled algorithm steps in exam questions.
排序方面,GCSE 考纲通常包括冒泡排序,有时涉及归并排序或插入排序。冒泡排序比较相邻元素并在顺序错误时交换,进行多轮遍历。归并排序采用分治方法:拆分、递归排序、合并。你应该理解它们的效率,并能在考试题目中补全部分完成算法步骤。
12. Debugging and Trace Tables | 调试与跟踪表
A trace table is a manual tool used to step through code line by line, recording the values of variables, conditions, and outputs. It is the most effective way to identify logic errors and is frequently tested. Set up columns for each variable and condition, and update the table after every line is executed.
跟踪表是一种手工工具,用于逐行执行代码并记录变量、条件和输出的值。它是识别逻辑错误最有效的方法,也是常考内容。为每个变量和条件设置列,并在每行执行后更新表格。
Debugging involves finding and fixing errors. Syntax errors are caught by the compiler/interpreter; logic errors produce wrong results but no crash; run‑time errors happen during execution (e.g., division by zero). Be methodical: use print statements, trace tables, and test normal, boundary, and erroneous data to ensure your program is robust.
调试包括查找和修正错误。语法错误被编译器/解释器捕获;逻辑错误产生错误结果但不会崩溃;运行时错误发生在执行过程中(例如除以零)。要有条理:使用输出语句、跟踪表,并测试正常、边界和错误数据以确保程序健壮。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导