← 返回资讯屏轩教育 · 行业资讯

IB CIE Computer Science: Programming Fundamentals Revision | IB CIE 计算机:编程基础考点精讲

2026-07-13 10:23 · 本文部分内容由AI辅助创作

📚 IB CIE Computer Science: Programming Fundamentals Revision | IB CIE 计算机:编程基础考点精讲

Mastering programming fundamentals is the cornerstone of success in both IB and CIE Computer Science examinations. This article systematically reviews key concepts, from variables and control flow to arrays and basic algorithms, providing clear explanations and practical examples. Each section is carefully aligned with the assessment objectives common to IB Computer Science (Standard/Higher Level) and CIE 9618/0478 syllabi, helping you build a rock-solid foundation for problem-solving and coding tasks.

掌握编程基础是在 IB 和 CIE 计算机科学考试中取得成功的基石。本文系统梳理了从变量、控制流到数组和基础算法的核心考点,并配有清晰的解释和实用示例。每节内容均紧扣 IB 计算机科学(SL/HL)与 CIE 9618/0478 课程大纲的评估目标,帮助你为解决问题和编程任务打下牢固的基础。

1. Programming Languages and Paradigms | 编程语言与范式

A programming language is a formal set of instructions used to communicate with a computer. High-level languages such as Python, Java, and C# are closest to human language and must be translated into machine code by a compiler or interpreter. The IB and CIE syllabi expect you to understand the distinction between low-level and high-level languages, as well as the concept of procedural programming – the dominant paradigm in the early stages of learning where programs are broken into procedures or functions.

编程语言是用于与计算机通信的一套形式化指令。Python、Java 和 C# 等高级语言最接近人类语言,必须由编译器或解释器转换为机器码。IB 和 CIE 课程要求你理解低级语言与高级语言的区别,以及过程式编程的概念——这种范式在初学阶段占主导地位,程序被分解为过程或函数。

Procedural languages execute statements in a sequential, top-down fashion, often using constructs like sequence, selection, and iteration. While object-oriented principles are introduced later, your foundation rests on these imperative building blocks. Knowing how a source program is compiled or interpreted helps in debugging and understanding runtime errors.

过程式语言以顺序、自上而下的方式执行语句,通常使用顺序、选择和迭代等结构。尽管后续会引入面向对象概念,你的基础仍建立在这些命令式构件上。理解源程序如何编译或解释有助于调试和认识运行时错误。


2. Variables and Data Types | 变量与数据类型

A variable is a named storage location in memory that holds a value which can be changed during program execution. Before using a variable, you must declare it with a data type (in statically-typed languages) or simply assign a value (in dynamically-typed languages like Python). Common primitive data types include integer, real/float, Boolean, and char. CIE 9618 also includes composite types such as record and array.

变量是内存中已命名的存储位置,其值在程序执行期间可以改变。使用变量前,你需要在静态类型语言中声明其数据类型,或在像 Python 这样的动态类型语言中直接赋值。常见的原始数据类型包括整型、实型/浮点型、布尔型和字符型。CIE 9618 还包括记录和数组等复合类型。

Data TypeExample ValueTypical Memory
Integer-42, 0, 20244 bytes
Float (Real)3.14, -0.0014 or 8 bytes
BooleanTrue, False1 byte
Char'A', '9', '&'1 byte (ASCII)
String"Hello"Variable

Choose appropriate data types to minimise memory usage and ensure deterministic behaviour. For instance, storing a person's age as an integer makes more sense than as a string. Constants are named values that never change; they improve readability and should be declared using a const or final keyword in many languages.

选择恰当的数据类型可以最小化内存使用并确保行为确定。例如,将人的年龄存储为整数远比存储为字符串合理。常量是值永不变更的命名项;它们能提高可读性,在许多语言中应使用 const 或 final 关键字声明。


3. Operators and Expressions | 运算符与表达式

Operators are symbols that tell the compiler or interpreter to perform specific mathematical, relational, or logical operations. Arithmetic operators (+ - * / MOD DIV) act on numeric operands; DIV returns integer quotient while MOD gives the remainder. Relational operators (== != > < >= <=) compare values and produce a Boolean result. Logical operators (AND, OR, NOT) combine Boolean expressions.

运算符是告诉编译器或解释器执行特定数学、关系或逻辑操作的符号。算术运算符(+ - * / MOD DIV)作用于数值操作数;DIV 返回整数商,而 MOD 返回余数。关系运算符(== != > < >= <=)比较值并产生布尔结果。逻辑运算符(AND, OR, NOT)用于组合布尔表达式。

Expressions evaluate to a single value and follow operator precedence. In most languages, multiplication and division take precedence over addition and subtraction. Use parentheses to override the default order. For the CIE examination, you must be able to construct truth tables for expressions like (A AND B) OR NOT C and predict the outcome of statements involving integer division.

表达式会计算出一个值并遵循运算符优先级。在大多数语言中,乘法和除法优先于加法和减法。可使用圆括号覆盖默认顺序。为应对 CIE 考试,你必须能够为类似 (A AND B) OR NOT C 的表达式构造真值表,并预测包含整数除法的语句的输出结果。


4. Input and Output Operations | 输入与输出操作

Input and output (I/O) allow a program to interact with the user or external devices. Basic console I/O commands include INPUT (or input() in Python) to capture data from the keyboard, and PRINT (or print()) to display information on screen. In pseudocode used by CIE, READ and WRITE are standard keywords for file operations, while OUTPUT is used for console display.

输入与输出(I/O)使程序能够与用户或外部设备交互。基本的控制台 I/O 命令包括用于从键盘捕获数据的 INPUT(或 Python 中的 input()),以及用于在屏幕上显示信息的 PRINT(或 print())。在 CIE 使用的伪代码中,READ 和 WRITE 是文件操作的标准关键词,而 OUTPUT 用于控制台显示。

When reading input, always consider data type conversion: the input function often returns a string, so you may need INT() or FLOAT() typecasting before using the value in calculations. Formatting output with fixed decimal places or column alignment is frequently tested. For example, to display a real number to 2 decimal places, you might use PRINT ROUND(value, 2).

读取输入时务必考虑数据类型转换:输入函数通常返回字符串,因此你可能需要先通过 INT() 或 FLOAT() 进行类型转换,再在计算中使用。将输出格式化为固定小数位数或列对齐是常考内容。例如,要将一个实数显示为两位小数,可使用 PRINT ROUND(value, 2)。


5. Conditional Statements | 条件语句

Conditional statements allow a program to make decisions and branch execution. The fundamental structure is the IF...THEN...ELSE construct. In CIE-style pseudocode, the syntax is:

条件语句允许程序做出决策并分支执行。基本结构是 IF...THEN...ELSE 结构。在 CIE 风格的伪代码中,语法为:

IF condition THEN
  statements
ELSE
  statements
ENDIF

A common pitfall is forgetting the ENDIF keyword or misplacing nested IF blocks. Complex conditions can be built using logical operators such as AND and OR. The CASE (or SWITCH) statement provides a cleaner alternative when testing the same variable against multiple constant values, improving readability and reducing Boolean complexity.

常见易错点包括遗忘 ENDIF 关键词或错误放置嵌套的 IF 代码块。可以使用 AND、OR 等逻辑运算符构建复杂条件。当需要针对多个常量值测试同一变量时,CASE(或 SWITCH)语句提供了更清晰的替代方案,能提升可读性并降低布尔表达式的复杂度。

In IB Computer Science, emphasis is placed on using decision constructs to implement algorithms such as grade calculators or simple menu systems. Always test boundary conditions – for instance, when checking scores, ensure that IF score >= 90 does not accidentally overlap with the next range.

在 IB 计算机科学中,重点在于使用决策结构实现诸如成绩计算器或简单菜单系统等算法。务必测试边界条件——例如,在检查分数时,要确保 IF score >= 90 不会与下一区间意外重叠。


广告 / Sponsored

6. Loops and Iteration | 循环与迭代

Loops enable repeated execution of a code block. The three main types are FOR (count-controlled), WHILE (pre-condition), and REPEAT...UNTIL (post-condition). A FOR loop iterates a known number of times, such as FOR i ← 1 TO 10. The WHILE loop checks the condition before each iteration, so the loop body may execute zero times. A REPEAT...UNTIL loop runs at least once because the condition is tested at the end.

循环使一个代码块能够重复执行。三种主要类型是 FOR(计数控制)、WHILE(前置条件)和 REPEAT...UNTIL(后置条件)。FOR 循环迭代已知次数,例如 FOR i ← 1 TO 10。WHILE 循环在每次迭代前检查条件,因此循环体可能执行零次。REPEAT...UNTIL 循环至少运行一次,因为条件在结尾处检查。

Choosing the correct loop structure is a key skill. Use a FOR loop when you know the exact number of iterations, a WHILE loop when the continuation depends on a dynamic condition, and REPEAT...UNTIL when you must guarantee at least one pass. Nested loops are often used to process 2D arrays or produce patterns; be aware of their O(n²) time complexity.

选择正确的循环结构是一项关键技能。当确知迭代次数时使用 FOR 循环;当继续条件取决于动态状态时使用 WHILE 循环;当必须保证至少执行一次时使用 REPEAT...UNTIL。嵌套循环常用于处理二维数组或输出图案;要注意其 O(n²) 的时间复杂度。

Avoid infinite loops by ensuring that the loop control variable is updated inside the body and eventually satisfies the exit condition. In pseudocode, an infinite loop might be written as WHILE TRUE DO...ENDWHILE and must contain a deliberate break mechanism.

避免无限循环,确保循环控制变量在循环体内被更新并最终满足退出条件。在伪代码中,无限循环可能写作 WHILE TRUE DO...ENDWHILE,且必须包含一个有意设置的跳出机制。


7. Functions and Procedures | 函数与过程

A function is a named block of code that returns a value, while a procedure (or subroutine) performs a task without returning a value. In modular design, breaking a problem into smaller, reusable units enhances readability and maintainability. IB and CIE both stress the importance of parameter passing – by value (a copy is passed) and by reference (the original variable can be modified).

函数是一个返回值的命名代码块,而过程(或子程序)执行任务但不返回值。在模块化设计中,将问题分解为更小、可复用的单元可以提高可读性和可维护性。IB 和 CIE 都强调参数传递的重要性——按值传递(传递副本)和按引用传递(可修改原始变量)。

When you define a function, you specify its signature: the name, parameters (with types if required), and return type. For example, FUNCTION Max(a: INTEGER, b: INTEGER) RETURNS INTEGER. Local variables declared inside a function have block scope and are not accessible outside. In contrast, global variables exist for the entire program and should be used sparingly due to the risk of side effects.

定义函数时,需指定其签名:名称、参数(必要时含类型)和返回类型。例如 FUNCTION Max(a: INTEGER, b: INTEGER) RETURNS INTEGER。在函数内部声明的局部变量具有块作用域,无法在外部访问。而全局变量存在于整个程序中,因可能导致副作用而应谨慎使用。

Recursion, where a function calls itself, is a powerful technique often applied to problems like factorial calculation or tree traversal. Every recursive solution must include a base case to stop the chain. For instance, FUNCTION Factorial(n) IF n = 0 THEN RETURN 1 ELSE RETURN n * Factorial(n-1).

递归是一种强大的技术,函数调用自身,常用于阶乘计算或树遍历等问题。每个递归解法都必须包含一个基本情况来终止调用链。例如 FUNCTION Factorial(n) IF n = 0 THEN RETURN 1 ELSE RETURN n * Factorial(n-1)。


8. Arrays and Strings | 数组与字符串

An array is a collection of elements of the same data type stored contiguously in memory. Arrays can be one-dimensional (a list), two-dimensional (a table/matrix), or multi-dimensional. Indexing typically starts at 0 or 1 depending on the language; in CIE pseudocode, lower-bound is often 1. Understanding linear storage of 2D arrays (row-major and column-major order) is expected at higher tiers.

数组是内存中连续存储的相同数据类型的元素集合。数组可以是一维(列表)、二维(表格/矩阵)或多维的。索引通常从 0 或 1 开始,取决于语言;在 CIE 伪代码中,下界常为 1。在高级别考试中,需要理解二维数组的线性存储方式(行主序和列主序)。

Strings are essentially arrays of characters. Common operations include concatenation, substring extraction, length determination (LEN(str)), and character retrieval. Many exam questions ask you to traverse a string using a loop to count vowels, reverse the string, or check for palindromes.

字符串本质上是字符数组。常见操作包括连接、提取子串、求长度(LEN(str))和检索字符。许多考题要求你使用循环遍历字符串,以统计元音字母、反转字符串或检查回文。

When implementing algorithms such as linear search on an array, always ensure the index stays within bounds. For example, WHILE (index <= length) AND (array[index] != target) DO index ← index + 1. In IB Paper 4 (HL) and CIE practical papers, you may be required to manipulate 2D arrays to rotate images or perform matrix multiplication.

在实现诸如数组线性搜索等算法时,务必确保索引不越界。例如 WHILE (index <= length) AND (array[index] != target) DO index ← index + 1。在 IB 试卷 4(HL)和 CIE 实践试卷中,你可能需要操作二维数组以实现图像旋转或矩阵乘法。


9. Basic Searching and Sorting Algorithms | 基本查找与排序算法

Two fundamental searching approaches are linear search and binary search. Linear search checks each element sequentially; it works on unsorted data and has O(n) time complexity. Binary search repeatedly divides a sorted array in half, achieving O(log n) performance. The pseudocode for binary search must handle the case where the item is not found, typically returning -1.

两种基本查找方法是线性搜索和二分搜索。线性搜索按顺序检查每个元素;它适用于未排序数据,时间复杂度为 O(n)。二分搜索反复将已排序数组对半分,达到 O(log n) 的性能。二分搜索的伪代码必须处理未找到目标的情况,通常返回 -1。

Sorting algorithms include bubble sort (repeated pairwise swapping) and insertion sort (building a sorted portion). Bubble sort has O(n²) worst-case complexity and is easy to remember: FOR i ← 1 TO n-1 and an inner loop that bubbles the largest element to the end. You should be able to dry-run these algorithms and count the number of comparisons and swaps.

排序算法包括冒泡排序(重复的成对交换)和插入排序(构建有序部分)。冒泡排序的最差时间复杂度为 O(n²) 且容易记忆:FOR i ← 1 TO n-1 以及一个将最大元素“冒泡”至末尾的内层循环。你应该能够手动运行这些算法并统计比较和交换的次数。

Although more efficient algorithms like quicksort and mergesort are introduced later, the foundation relies on these simpler sorts. Exams often present a partially sorted list and ask you to show the state after the first pass of bubble sort or after insertions.

尽管后续会引入快速排序和归并排序等更高效的算法,但基础仍依赖于这些简单排序。考试中常给出一个部分有序的列表,要求你展示冒泡排序第一趟之后的状态,或插入排序各步后的结果。


10. Debugging and Good Practices | 调试与编程规范

Testing and debugging are integral parts of software development. A syntax error violates the language’s grammar rules and is caught at compile time. A logic error produces incorrect results even though the code runs without crashing; you must use trace tables, print statements, or a debugger to locate it. Run-time errors (e.g., division by zero, file not found) occur during execution and can crash the program if not handled.

测试与调试是软件开发不可或缺的部分。语法错误违反语言的语法规则,在编译时被捕获。逻辑错误即使代码正常运行也会产生不正确的结果;你必须借助跟踪表、输出语句或调试器来定位。运行时错误(如除零、文件未找到)在执行期间发生,若未处理则可能导致程序崩溃。

Adopting good coding practices is explicitly rewarded in both IB and CIE assessments. Meaningful variable names, consistent indentation, and concise comments help others (and yourself) understand the logic. Use comments to explain the purpose of a block, not to restate obvious operations. Avoid magic numbers by defining constants like MAX_SIZE ← 100.

在 IB 和 CIE 的评估中,采用良好的编码规范会得到明确奖励。有意义的变量名、一致的缩进和简洁的注释能帮助他人(以及你自己)理解逻辑。使用注释解释代码块的用途,而非复述显而易见的操作。通过定义如 MAX_SIZE ← 100 这样的常量来避免“魔法数字”。

Modular design, adequate white space, and a simple, uncluttered style will make your exam script stand out. For practical papers, always save your work frequently and test each module incrementally. These habits are not only exam-savvy but also prepare you for real-world collaborative coding.

模块化设计、适当的留白以及简洁明了的风格将使你的答卷脱颖而出。在实践考试中,务必经常保存工作并逐步测试每个模块。这些习惯不仅利于考试,也为你在现实世界的协作编程中做好准备。


Published by TutorHao | Computer Science Revision Series | aleveler.com

广告 / Sponsored
IBDP国际文凭计算机科学学生用书 高级及标准水平 Computer Science for the IB Diplo…
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥524.0

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao