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

1. Programming Concepts | 编程概念

2026-08-03 04:53 · 本文部分内容由AI辅助创作

📚 1. Programming Concepts | 编程概念

Programming is the process of designing and writing instructions that tell a computer how to perform a specific task. In IGCSE Computer Science, grasping the fundamental concepts of programming is essential for problem-solving, algorithm design, and writing efficient code. These concepts—such as sequence, selection, iteration, variables, and data types—form the building blocks of all computer programs, regardless of the language used. Mastering them will help you think computationally and prepare you for both the theory and practical components of the examination.

编程是设计并编写指令的过程,这些指令告诉计算机如何执行特定的任务。在IGCSE计算机科学课程中,掌握基本的编程概念对于问题求解、算法设计和编写高效代码至关重要。这些概念——例如顺序、选择、迭代、变量和数据类型——构成了所有计算机程序的基石,无论使用哪种编程语言。熟练掌握这些概念将帮助你发展计算思维,并为考试的理论部分和实践部分做好准备。


1. What is Programming? | 什么是编程?

Programming is the act of creating a set of instructions that a computer can follow to accomplish a goal. These instructions are written in a programming language such as Python, Java, or pseudocode. A program takes input, processes it, and produces output. The key to good programming is writing clear, logical, and efficient code that solves the intended problem correctly.

编程是创建一组指令的行为,计算机可以遵循这些指令达成某个目标。这些指令是用编程语言编写的,例如Python、Java或伪代码。一个程序接收输入,对其进行处理,然后产生输出。好的编程关键在于编写清晰、逻辑性强且高效的代码,能够正确地解决预期的问题。


2. Algorithms and Flowcharts | 算法与流程图

An algorithm is a step-by-step procedure for solving a problem. Before writing code, programmers often design algorithms using pseudocode or flowcharts. A flowchart uses standard symbols—ovals for start/end, parallelograms for input/output, rectangles for processes, and diamonds for decisions—to represent the flow of logic visually. This helps in planning the structure of a program and spotting errors early.

算法是解决问题的逐步过程。在编写代码之前,程序员通常使用伪代码或流程图来设计算法。流程图使用标准符号——椭圆表示开始/结束,平行四边形表示输入/输出,矩形表示处理步骤,菱形表示判断——来直观地表示逻辑流程。这有助于规划程序的结构并及早发现错误。


3. Sequence, Selection, and Iteration | 顺序、选择和迭代

The three fundamental programming constructs are sequence, selection, and iteration. Sequence means executing instructions one after another in order. Selection involves making decisions using conditions (e.g., IF...THEN...ELSE). Iteration means repeating a block of code, either a fixed number of times (FOR loop) or while a condition is true (WHILE loop). Together, these three constructs can express any algorithm.

三个基本的编程结构是顺序、选择和迭代。顺序意味着按照顺序逐条执行指令。选择涉及使用条件进行决策(例如 IF...THEN...ELSE)。迭代意味着重复执行一段代码,可以是固定次数(FOR循环),也可以在条件为真时重复(WHILE循环)。这三种结构组合起来可以表达任何算法。


4. Variables and Constants | 变量与常量

A variable is a named storage location in memory that can hold a value which may change during program execution. For example, score ← 0 assigns 0 to the variable score. A constant is similar but its value cannot be changed after it is assigned, e.g., PI ← 3.14. Using meaningful variable names such as totalMarks rather than x makes code easier to understand.

变量是内存中已命名的存储位置,可以保存一个在程序执行期间可能会变化的值。例如,score ← 0 将0赋给变量 score。常量与之类似,但在赋值之后其值不能改变,例如 PI ← 3.14。使用有意义的变量名如 totalMarks 而非 x,可以使代码更易于理解。


5. Data Types | 数据类型

Every variable has a data type that defines what kind of data it can store. Common primitive types include integer (whole numbers, e.g., 42), real/float (decimal numbers, e.g., 3.14), char (a single character, e.g., 'A'), string (a sequence of characters, e.g., "hello"), and Boolean (TRUE or FALSE). Choosing the correct data type is important for memory usage and data manipulation.

每个变量都有一个数据类型,定义了它可以存储何种数据。常见的简单类型包括整数(integer,例如42)、实数/浮点数(real/float,例如3.14)、字符(char,单个字符,例如'A')、字符串(string,字符序列,例如"hello")和布尔型(Boolean,TRUE或FALSE)。选择正确的数据类型对于内存使用和数据操作非常重要。


6. Input and Output | 输入与输出

Programs communicate with the user through input and output operations. Input statements read data from the keyboard or a file, storing it in variables. For example, INPUT name reads a string into the variable name. Output statements display information on the screen, e.g., OUTPUT "Hello" or PRINT total. Effective use of I/O makes programs interactive and useful.

程序通过输入和输出操作与用户交流。输入语句从键盘或文件读取数据,并将其存储在变量中。例如,INPUT name 将一个字符串读入变量 name。输出语句在屏幕上显示信息,例如 OUTPUT "Hello" 或 PRINT total。有效使用输入输出可以让程序具有交互性和实用性。


7. Assignment and Arithmetic Operators | 赋值与算术运算符

Assignment sets a variable to a value, often using the ← symbol or = sign. Arithmetic operators perform calculations: + (addition), − (subtraction), * (multiplication), / (division). Integer division (DIV or //) gives the quotient without remainder, while modulus (MOD or %) returns the remainder. The order of operations follows standard precedence (brackets, multiplication/division, addition/subtraction).

赋值语句将一个值设置给变量,通常使用 ← 符号或 = 号。算术运算符执行计算:+(加)、−(减)、*(乘)、/(除)。整除(DIV 或 //)给出不带余数的商,而取模运算(MOD 或 %)返回余数。运算顺序遵循标准优先级(括号、乘除、加减)。

OperatorExampleResult
+7 + 310
-7 - 34
*7 * 321
/7 / 32.333...
DIV7 DIV 32
MOD7 MOD 31

广告 / Sponsored

8. Relational and Logical Operators | 关系运算符与逻辑运算符

Relational operators compare values and return a Boolean TRUE or FALSE. Common operators include = (equal to), ≠ (not equal to), < (less than), > (greater than), ≤ (less than or equal to), and ≥ (greater than or equal to). Logical operators combine multiple conditions: AND (both true), OR (at least one true), and NOT (reverses truth value).

关系运算符比较两个值并返回布尔值 TRUE 或 FALSE。常用的运算符包括 =(等于)、≠(不等于)、<(小于)、>(大于)、≤(小于或等于)和 ≥(大于或等于)。逻辑运算符组合多个条件:AND(两者都为真)、OR(至少一个为真)和 NOT(反转真值)。

For instance, the expression (age ≥ 18) AND (passed = TRUE) evaluates to TRUE only if both conditions hold. These operators are essential for constructing selection and loop conditions.

例如,表达式 (age ≥ 18) AND (passed = TRUE) 只有当两个条件同时成立时才为 TRUE。这些运算符对于构建选择和循环条件至关重要。


9. Conditional Statements (IF-THEN-ELSE) | 条件语句(IF-THEN-ELSE)

Conditional statements allow a program to make decisions. The simplest form is IF condition THEN instruction. An ELSE clause provides an alternative when the condition is false. Cascaded IF statements (IF...ELSE IF...ELSE) handle multiple mutually exclusive paths. Nested IFs place one decision inside another, allowing more complex logic.

条件语句允许程序做出决策。最简单的形式是 IF condition THEN instruction。ELSE 子句在条件为假时提供一个备选路径。级联 IF 语句(IF...ELSE IF...ELSE)处理多个互斥的分支。嵌套 IF 将一条判断语句放在另一条内部,从而实现更复杂的逻辑。

Example pseudocode:

IF score ≥ 80 THEN
OUTPUT "A"
ELSE IF score ≥ 60 THEN
OUTPUT "B"
ELSE
OUTPUT "C"
ENDIF

示例伪代码:

IF score ≥ 80 THEN
OUTPUT "A"
ELSE IF score ≥ 60 THEN
OUTPUT "B"
ELSE
OUTPUT "C"
ENDIF


10. Loops: FOR, WHILE, and REPEAT | 循环:FOR、WHILE 和 REPEAT

Loops repeat a block of code. A FOR loop runs a fixed number of times, typically using a counter. For example, FOR i ← 1 TO 10 OUTPUT i NEXT i prints numbers 1 to 10. A WHILE loop repeats as long as a condition is true, testing at the start. A REPEAT...UNTIL loop executes at least once and tests the condition at the end.

循环重复执行一段代码。FOR 循环运行固定次数,通常使用计数器。例如,FOR i ← 1 TO 10 OUTPUT i NEXT i 会打印数字 1 到 10。WHILE 循环只要条件为真就重复,在循环开始处测试条件。REPEAT...UNTIL 循环至少执行一次,并在末尾测试条件。

Choosing the right loop depends on whether the number of iterations is known in advance or depends on a runtime condition. Infinite loops occur if the terminating condition is never met, causing the program to hang.

选择正确的循环取决于迭代次数是预先知道的还是依赖于运行时的条件。如果终止条件永远无法满足,就会出现无限循环,导致程序挂起。


11. Tracing and Dry Running | 跟踪与干运行

Tracing (or dry running) is a manual technique where you step through code line by line, recording the values of variables in a trace table. This method helps programmers understand program flow, identify logic errors, and verify correctness. It is an essential skill for the IGCSE paper, where you may be asked to complete a trace table for given pseudocode.

跟踪(或干运行)是一种手动技术,你逐行执行代码,在跟踪表中记录变量的值。这种方法有助于程序员理解程序流程、识别逻辑错误并验证正确性。这是IGCSE考试中的一项基本技能,你可能会被要求为给定的伪代码填写跟踪表。

A simple trace for a loop summing numbers would list each iteration, the loop counter, and the running total, making it easy to spot off-by-one errors or incorrect updates.

对一个求和的循环进行简单跟踪时,会列出每次迭代、循环计数器和累计总和,这样很容易发现差一错误或不正确的更新。


12. Testing and Debugging | 测试与调试

Testing ensures a program works as intended under all expected conditions. It involves selecting test data including normal (valid), boundary (edge cases), and erroneous (invalid) inputs. Debugging is the process of finding and fixing errors (bugs). Syntax errors break language rules, logic errors produce wrong results, and runtime errors occur during execution. Systematic testing improves reliability.

测试确保程序在所有预期条件下都能按预期工作。它涉及选择测试数据,包括正常数据(有效)、边界数据(边界情况)和错误数据(无效输入)。调试是发现并修正错误(bug)的过程。语法错误违反语言规则,逻辑错误产生错误的结果,运行时错误在执行过程中发生。系统化的测试可以提高程序的可靠性。

For example, testing a program that checks if a number is positive should include values like 5 (normal), 0 (boundary), -1 (negative), and a large number. These help verify that all branches are correct.

例如,测试一个检查数字是否为正数的程序时,应包含诸如5(正常)、0(边界)、-1(负数)和一个很大的数这样的值。这有助于验证所有分支都正确。


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

广告 / Sponsored
现货 Cambridge International AS & ALevel IT Coursebook剑桥国际IGC…
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥467.0

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

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