📚 GCSE WJEC Computer Science: Programming Fundamentals | GCSE WJEC 计算机:编程基础 考点精讲
Mastering programming fundamentals is essential for success in the WJEC GCSE Computer Science exam. This guide covers every topic you need, from data types and variables through selection, iteration, string handling, arrays and subprograms, right up to validation, testing and trace tables, with clear WJEC-style pseudocode examples and explanations at every step. Whether you are new to coding or revising for your final assessment, these focused sections will build your confidence and help you write correct, efficient algorithms under exam conditions.
掌握编程基础对于在 WJEC GCSE 计算机科学考试中取得好成绩至关重要。本指南涵盖你需要掌握的所有主题,从数据类型、变量,到选择结构、迭代、字符串处理、数组与子程序,再到验证、测试和跟踪表,每一步都配有清晰的 WJEC 风格伪代码示例和解释。无论你是编程新手还是为最终评估复习,这些简明章节都能建立你的自信,帮助你在考试条件下写出正确、高效的算法。
1. Variables and Constants | 变量与常量
altered once they have been set. In WJEC-style pseudocode, assignment uses a left arrow (←), so writing score ← ve names improve readability; a name must not contain spaces and must not begin with a digit.
变量是程序运行期间值可以改变的有名称的存储位置。常量存储一旦设定就不可更改的固定值。在 WJEC 风格的伪代码中,赋值使用左箭头(←),例如写 score ← 0 就是把 0 存入变量 score。常量使用关键字 CONST 声明,例如 CONST PI = 3.14 或 CONST MAX_MARKS = 100。描述性的名称有助于可读性;名称不能包含空格,也不能以数字开头。
Choosing a meaningful name matters in the exam. A variable called totalScore is far clearer than one called x, and examiners award marks for sensible identifiers as part of "quality of solution" grids.
在考试中,选择有意义的名称很重要。名为 totalScore 的变量远比名为 x 的变量清晰,评分标准中的"方案质量"部分也会为合理的标识符给分。
score ← 0
CONST MAX_MARKS = 100
Constants should be used whenever a value never changes during execution, such as the number of sides of a dice, a tax rate or the maximum mark in a test. Using a constant means that if the value must be updated later, only one line of code needs editing.
当某个值在程序执行期间永不改变时,就应当使用常量,例如骰子的面数、税率或测试的最高分。使用常量的好处是:日后若要修改该值,只需改动一行代码。
2. Data Types | 数据类型
Common data types are integer (whole numbers), real or float (decimal numbers), Boolean (True or False), character (a single symbol) and string (text). WJEC pseudocode does not force you to declare types explicitly, but you must choose the correct type for the operation you are performing. Storing a person's age requires an integer; storing a person's name requires a string.
常见的数据类型有整数(integer,整型)、实数(real/float,浮点数)、布尔值(Boolean,True/False)、字符(character,单个符号)和字符串(string,文本)。WJEC 伪代码不强制显式声明类型,但在执行操作时必须选择正确的类型。存储一个人的年龄需要整数类型,存储姓名则需要字符串类型。
ean is particularly important because it is the result of every comparison, such as hungry ← True or isFull ← count = 10. Mixing types causes errors: adding the string "5" to the integer 5 is not the same as adding 5 + 5.
布尔值尤其重要,因为每一次比较的结果都是布尔值,例如 hungry ← True 或 isFull ← count = 10。混用类型会导致错误:把字符串 "5" 与整数 5 相加,跟 5 + 5 的结果完全不同。
age ← 16
name ← "Priya"
| Type | Example value | 类型 | 示例值 |
| Integer | 42 | 整数 | 42 |
| Real | 3.14 | 实数 | 3.14 |
| Boolean | True | 布尔值 | True |
| Character | "A" | 字符 | "A" |
| String | "Hello" | 字符串 | "Hello" |
3. Input and Output | 输入与输出
Programs interact with users through INPUT and OUTPUT. OUTPUT displays a message or a value on screen; INPUT pauses the program and waits for the user to enter data, which is then stored in a variable. A well-written program always prompts the user first, so the user knows what is expected.
程序通过 INPUT 和 OUTPUT 与用户交互。OUTPUT 在屏幕上显示消息或数值;INPUT 会暂停程序,等待用户输入数据,然后把这些数据存入变量。规范的程序总是先给出提示信息,让用户知道需要输入什么。
OUTPUT "What is your name?"
name ← INPUT
OUTPUT "Hello " + name
Remember that INPUT normally returns a string, so a number entered by the user may need converting before arithmetic. Output can combine literal text and variables using concatenation, and each OUTPUT statement normally starts a new line on screen.
请记住,INPUT 通常返回字符串,因此用户输入的数字在做算术运算前可能需要类型转换。输出可以使用拼接把固定文本与变量组合起来,每条 OUTPUT 语句通常会在屏幕上另起一行。
4. Arithmetic Operators, DIV and MOD | 算术运算符、DIV 与 MOD
ion and ÷ or / for division, with brackets used to control the order of operations. Two special integer operators appear frequently in exam questions: DIV gives the whole-number part of a division and MOD gives the remainder.
WJEC 伪代码使用 + 表示加法、− 表示减法、× 表示乘法、÷ 或 / 表示除法,并用括号控制运算顺序。考试题中经常出现两个特殊的整数运算符:DIV 给出除法的整数部分,MOD 给出余数。
17 DIV 5 = 3
17 MOD 5 = 2
s working out how many full boxes of 12 eggs can be filled from 100 eggs (100 DIV 12 = 8).
MOD 是判断奇偶数的标准方法:如果 number MOD 2 = 0,则该数为偶数。DIV 用于把总数分组,例如计算 100 个鸡蛋能装满多少盒 12 个装的鸡蛋(100 DIV 12 = 8)。
Standard operator precedence applies: brackets first, then multiplication and division, then addition and subtraction. When in doubt, add brackets - they cost nothing and remove ambiguity for the examiner.
标准运算优先级同样适用:先算括号,再算乘除,最后算加减。拿不准时就加括号——括号不会扣分,还能为阅卷老师消除歧义。
5. Boolean Logic and Comparison Operators | 布尔逻辑与比较运算符
and <= (less than or equal to). These are combined with the logical operators AND, OR and NOT to build the conditions used in selection and iteration.
比较运算会产生布尔值:=(等于)、<>(不等于)、>(大于)、<(小于)、>=(大于或等于)和 <=(小于或等于)。它们再与逻辑运算符 AND、OR、NOT 组合,构成选择结构和迭代结构中使用的条件。
AND requires both sides to be True, OR requires at least one side to be True, and NOT reverses a value. Examiners often ask you to complete a truth table or to simplify a condition, so learn the patterns below.
AND 要求两边都为 True,OR 要求至少一边为 True,NOT 则把一个值取反。考官常要求你补全真值表或化简条件,因此请牢记下表规律。
| P | Q | P AND Q | P OR Q |
| False | False | False | False |
| False | True | False | True |
| True | False | False | True |
| True | True | True | True |
6. Selection: IF, ELSE and CASE | 选择结构:IF、ELSE 与 CASE
Selection allows a program to follow different paths depending on a condition. The basic form is IF...THEN...ELSE...ENDIF. The condition after IF is evaluated once; if it is True the THEN block runs, otherwise the ELSE block runs. Every IF must be closed with ENDIF.
选择结构让程序根据条件走不同的分支。基本形式是 IF...THEN...ELSE...ENDIF。IF 后面的条件只求值一次;若为 True 则执行 THEN 块,否则执行 ELSE 块。每个 IF 都必须用 ENDIF 结束。
IF mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
When one variable is compared against several fixed values, CASE...OF is clearer than a long chain of ELSEIF statements. It ends with OTHERWISE (the default branch) and is closed by ENDCASE.
当同一个变量要与多个固定值比较时,用 CASE...OF 比一长串 ELSEIF 更清晰。它以 OTHERWISE(默认分支)收尾,并用 ENDCASE 结束。
CASE menuChoice OF
1 : playGame()
2 : showScores()
OTHERWISE : OUTPUT "Invalid choice"
ENDCASE
Indentation is not just decoration: it shows the examiner exactly which statements belong inside which branch, and nested IF statements without clear indentation almost always lose marks.
缩进不只是装饰:它能向阅卷老师清楚展示哪些语句属于哪个分支,而缺少清晰缩进的嵌套 IF 几乎总会丢分。
7. Iteration: FOR, WHILE and REPEAT | 迭代结构:FOR、WHILE 与 REPEAT
Iteration repeats a block of code. A FOR loop is count-controlled because it repeats a known number of times, using a counter variable that is automatically increased by one on each pass. A WHILE loop is condition-controlled and tests its condition before each iteration, so its body may never run at all.
迭代用于重复执行一段代码。FOR 循环属于计数控制循环,因为它重复已知的次数,使用一个计数器变量,每轮自动加一。WHILE 循环属于条件控制循环,在每次迭代之前检查条件,因此循环体可能一次都不执行。
FOR i ← 1 TO 5
OUTPUT i
NEXT i
REPEAT...UNTIL is also condition-controlled, but it tests the condition after the body, so the body always runs at least once. This makes it ideal for input validation, where you must ask for a value before you can judge whether it is acceptable.
REPEAT...UNTIL 同样属于条件控制循环,但它在循环体执行之后才检查条件,因此循环体至少会执行一次。这使它非常适合输入验证——你必须先读取一个值,才能判断它是否可接受。
REPEAT
OUTPUT "Enter a mark from 0 to 100"
mark ← INPUT
UNTIL mark >= 0 AND mark <= 100
A common exam task is to state how many times a loop runs or what the final value of a counter is. Trace the loop by hand, writing the counter value after each pass, and remember that a FOR loop from 0 TO 9 runs exactly ten times.
常见考题是写出循环执行了多少次,或循环结束后计数器的最终值。请手工跟踪循环,每轮结束后写下计数器值,并记住:从 0 TO 9 的 FOR 循环正好执行十次。
8. String Handling | 字符串处理
Strings are sequences of characters, and WJEC expects you to use standard string operations: finding the length, extracting a substring, converting case and joining strings together. Substrings are usually specified by a start position and an end position, counting from zero.
字符串是字符的序列,WJEC 要求你会使用标准字符串操作:求长度、提取子串、转换大小写以及拼接字符串。子串通常用起始位置和结束位置来指定,并且从 0 开始计数。
word ← "Computer"
word.length → 8
word.substring(0, 4) → "Comp"
word.toUpperCase() → "COMPUTER"
Characters can also be converted to and from their character codes, which is how programs sort text, check for digits or build simple ciphers. A Caesar cipher, for instance, adds a fixed number to each character code and converts the result back to a character.
字符还可以与其字符编码互相转换,程序正是借此对文本排序、判断是否为数字字符,或实现简单的加密。例如凯撒密码就是把每个字符的编码加上一个固定的数字,再把结果转回字符。
Always check whether a position is inside the string before extracting a substring. Taking characters beyond the end of a string is a classic source of runtime errors in exam scenarios.
在提取子串之前,务必先检查位置是否落在字符串范围内。取超出字符串末尾的字符,是考试情境中典型的运行时错误来源。
9. Data Structures: Arrays and Lists | 数据结构:数组与列表
An array stores many values of the same type under a single name, and each value is accessed by its index. WJEC pseudocode arrays are zero-indexed for the purposes of the specification, so an array of five elements uses indexes 0 to 4.
数组在同一个名称下存储多个同类型的值,每个值通过索引访问。按照 WJEC 规范,伪代码数组从 0 开始索引,因此一个含五个元素的数组使用的索引是 0 到 4。
scores ← [0, 0, 0, 0, 0]
scores[0] ← 45
OUTPUT scores[0]
Arrays become powerful when combined with iteration. A single FOR loop can read every element, sum them, count how many pass a threshold or find the largest value - far shorter and safer than writing five separate statements.
数组与迭代结合后威力巨大。一个 FOR 循环就能读取每个元素、求总和、统计有多少个达到阈值,或找出最大值——这比写五条独立语句短得多,也安全得多。
total ← 0
FOR i ← 0 TO 4
total ← total + scores[i]
NEXT i
Linear search and bubble sort are the two standard array algorithms on this specification. A linear search checks each element in turn until it finds a match; a bubble sort repeatedly compares adjacent pairs and swaps them if they are in the wrong order, stopping early once a full pass makes no swaps.
线性查找和冒泡排序是本规范中的两个标准数组算法。线性查找依次检查每个元素直到找到匹配项;冒泡排序反复比较相邻元素,若顺序错误就交换,某一轮没有任何交换时即可提前结束。
10. Subprograms: Functions and Procedures | 子程序:函数与过程
Subprograms break a large problem into smaller, reusable pieces. A function returns a single value and is called inside an expression; a procedure performs a task but returns nothing. Both accept parameters, which are the values passed in when the subprogram is called.
子程序把大问题拆分成更小、可复用的部分。函数返回一个值,并在表达式中被调用;过程执行一个任务但不返回值。两者都可以接收参数,也就是调用子程序时传入的值。
FUNCTION area(length, width)
RETURN length × width
ENDFUNCTION
PROCEDURE greet(name)
OUTPUT "Hello, " + name
更多咨询请联系16621398022(同微信)
或截图后用「扫一扫 → 相册」选择本图