Combined Programming Operations: Sequence, Selection, Iteration and Data Structures | 编程综合操作:顺序、选择、迭代与数据结构

📚 Combined Programming Operations: Sequence, Selection, Iteration and Data Structures | 编程综合操作:顺序、选择、迭代与数据结构

In Edexcel A-Level programming, exam questions often combine several basic operations into one scenario. You may be asked to trace code that uses sequence, selection, iteration, arrays, stacks, queues and subroutines at the same time. This revision article explains the combined operations you are most likely to meet and how to handle them accurately.

在 Edexcel A-Level 编程考试中,题目经常把多个基本操作组合到一个情境中。你可能需要跟踪同时使用顺序、选择、迭代、数组、栈、队列和子程序的代码。本篇复习文章讲解你最可能遇到的综合操作,以及如何准确处理它们。


1. Programming Constructs Overview | 编程结构总览

In Edexcel A-Level programming, you must be able to recognise how sequence, selection and iteration work together inside one algorithm. A single exam question may require you to read a loop that contains an IF statement, updates an array and calls a function. You should therefore practice tracing combined code rather than only isolated syntax.

在 Edexcel A-Level 编程中,你必须能够识别顺序、选择和迭代如何在一个算法中协同工作。一道考试题可能要求你阅读一个循环,其中包含 IF 语句、更新数组并调用函数。因此,你应当练习跟踪组合代码,而不仅仅是孤立地记忆语法。

The three constructs are the building blocks of structured programming. Sequence gives the order, selection gives branching, and iteration gives repetition. When combined, they allow you to model complex real-world problems such as processing customer orders, simulating a checkout queue or searching a list of records.

这三种结构是结构化编程的基本构件。顺序给出执行次序,选择给出分支,迭代给出重复。它们组合起来后,就能为处理客户订单、模拟结账队列或搜索记录列表等复杂现实问题建模。

In the Edexcel pseudocode, these constructs are written using keywords such as IF, THEN, ELSE, END IF, FOR, WHILE, REPEAT and UNTIL. You should always read the whole algorithm before starting a trace, because later operations may change variables that were set earlier.

在 Edexcel 伪代码中,这些结构使用 IF、THEN、ELSE、END IF、FOR、WHILE、REPEAT 和 UNTIL 等关键字。在开始跟踪之前,你应当先通读整个算法,因为后面的操作可能会改变前面设置的变量。


2. Sequence: Order Matters | 顺序:执行顺序至关重要

Sequence means statements execute one after another from top to bottom. A common mistake is to think that swapping two variables can be done with only two assignments. In fact, you need a temporary variable to preserve one value before overwriting it.

顺序意味着语句从上到下依次执行。一个常见错误是认为仅用两条赋值语句就能交换两个变量。实际上,你需要一个临时变量在覆盖之前保存其中一个值。

temp ← a; a ← b; b ← temp

For example, if a = 5 and b = 9, copying a into temp first keeps the 5 safe. Then a can take b’s value and b can take the saved value. Without the temporary variable, both variables would end up storing the same number.

例如,如果 a = 5 且 b = 9,先将 a 复制到 temp 可以保住 5。然后 a 可以接收 b 的值,b 可以接收保存下来的值。如果没有临时变量,两个变量最终都会存储同一个数字。

Sequence also includes initialisation before a loop and output after a loop. In many combined questions, a counter or total must be set to 0 before the loop begins. If this initialisation is placed inside the loop, the value will be reset every iteration and the result will be incorrect.

顺序还包括循环前的初始化和循环后的输出。在许多综合题中,计数器或总额必须在循环开始前设置为 0。如果这个初始化放在循环内部,该值每次迭代都会被重置,结果就会出错。


3. Selection: Making Decisions | 选择:做出判断

Selection uses conditions to decide which block of code should run. In Edexcel pseudocode, this may appear as IF…THEN…ELSE…END IF or as a CASE statement when there are many distinct values. Nested selection means one IF statement is placed inside another branch.

选择使用条件来决定运行哪一段代码。在 Edexcel 伪代码中,它可能以 IF…THEN…ELSE…END IF 出现,或在有多个离散值时使用 CASE 语句。嵌套选择意味着一个 IF 语句放在另一个分支内部。

When combining selection with loops, you must watch whether the condition is checked before or after each iteration. A pre-checked loop may never run if the condition is initially false; a post-checked loop always runs at least once. This distinction is often tested with WHILE versus REPEAT UNTIL.

当选择与循环结合时,必须注意条件是在每次迭代之前还是之后检查。前测循环如果条件一开始为假,可能一次都不运行;后测循环则至少运行一次。这个区别经常通过 WHILE 与 REPEAT UNTIL 来考查。

Another common pattern is the ELSE IF chain. It lets you test several conditions in order and execute only the first branch whose condition is true. If no condition is true, the final ELSE branch runs. This pattern is useful for grading systems, menu choices and validation rules.

另一个常见模式是 ELSE IF 链。它允许你依次测试多个条件,并且只执行第一个为真的分支。如果没有条件为真,则运行最后的 ELSE 分支。这种模式适用于评分系统、菜单选择和验证规则。

IF score ≥ 80 THEN grade ← ‘A’ ELSE IF score ≥ 70 THEN grade ← ‘B’ END IF

When tracing an ELSE IF chain, move down the conditions one by one. Once a branch executes, skip all remaining branches in that structure. Do not test later conditions after one has already been chosen.

跟踪 ELSE IF 链时,要逐个向下检查条件。一旦某个分支执行,就跳过该结构中所有剩余分支。在一个分支被选中后,不要再测试后面的条件。


4. Iteration: Repeating Efficiently | 迭代:高效重复

Iteration repeats a block of code. Count-controlled iteration uses a loop variable such as FOR i ← 1 TO n. Condition-controlled iteration uses WHILE or REPEAT UNTIL and depends on a Boolean expression that changes inside the loop.

迭代重复执行一段代码。计数控制迭代使用循环变量,例如 FOR i ← 1 TO n。条件控制迭代使用 WHILE 或 REPEAT UNTIL,依赖在循环内部发生变化的布尔表达式。

Many combined operations involve an accumulator and a counter. An accumulator adds up values, while a counter counts how many items meet a condition. If these variables are not initialised to 0 before the loop, the final answer will be wrong.

许多组合操作涉及累加器和计数器。累加器把数值相加,计数器统计满足某个条件的项有多少个。如果这些变量在循环前没有初始化为 0,最终答案就会出错。

For example, to count how many marks in a list are greater than 50, you can loop through the list and increase a counter for each qualifying mark. The same loop could also add all qualifying marks to a total, giving you both the count and the sum in one pass.

例如,要统计列表中有多少个分数大于 50,你可以遍历列表,并为每个符合条件的分数增加计数器。同一个循环还可以把所有符合条件的分数加入总额,这样一次遍历就能同时得到个数和总和。

Be careful with loop bounds. If an array has n elements indexed from 0 to n-1, a FOR loop should run from 0 to n-1, not from 0 to n. Using n as the upper bound causes an index out of range error in many languages.

注意循环边界。如果一个数组有 n 个元素,索引从 0 到 n-1,那么 FOR 循环应从 0 运行到 n-1,而不是从 0 到 n。把 n 作为上界会在许多语言中导致索引越界错误。


5. Combining Arithmetic Operators | 组合算术运算符

Arithmetic operators must be applied in the correct order: brackets first, then multiplication and division, then addition and subtraction. Integer division and modulus are especially common in A-Level questions because they are used to separate digits, identify odd or even numbers or wrap around an index.

算术运算符必须按正确顺序应用:先括号,后乘除,再加减。整数除法和取模在 A-Level 题目中尤其常见,因为它们用于分离数字、判断奇偶或使索引回绕。

Operator | 运算符 Meaning | 含义 Example | 示例
+ Addition | 加法 7 + 3 = 10
Subtraction | 减法 7 – 3 = 4
× Multiplication | 乘法 7 × 3 = 21
÷ 更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading