# 控制 Control


# Grade 2 ( 5-7岁 ) 要掌握的程度

Computers follow precise sequences of instructions that automate tasks. Program execution can also be nonsequential by repeating patterns of instructions and using events to initiate instructions.

Computers follow instructions literally. Examples of sequences of instructions include steps for drawing a shape or moving a character across the screen. An event, such as the press of a button, can trigger an action. Simple loops can be used to repeat instructions. At this level, distinguishing different types of loops is not expected.

Crosscutting Concept: Abstraction Connection Within Framework: K–2.Data and Analysis.Storage

计算机会严格按照代码制定的顺序执行, 使任务执行自动化. 同时, 程序的执行也可以通过重复指令的模式以及通过“事件”[1]来启动相应的代码指令, 以实现非序列化的执行.

计算机会遵循代码指令的字面意思[2].

  • 按代码指定顺序执行的例子: 画一个形状、在屏幕上移动一个字符
  • 编程的“事件”, 比如按下按钮, 触发计算机的某个操作

简单的循环可以使用重复指令. 但是对于这个阶段的学生, 不需要区分不同的循环类型.


# Grade 5 ( 8-11岁 ) 要掌握的程度

Control structures, including loops, event handlers, and conditionals, are used to specify the flow of execution. Conditionals selectively execute or skip instructions under different conditions.

Different types of loops are used to repeat instructions in multiple ways depending on the situation. Examples of events include mouse clicks, typing on the keyboard, and collisions between objects. Event handlers are sets of commands that are tied to specific events. Conditionals represent decisions and are composed of a Boolean condition that specifies actions based on whether the condition evaluates to true or false. Boolean logic and operators (e.g., AND, OR, NOT) can be used to specify the appropriate groups of instructions to execute under various conditions.

Crosscutting Concepts: Abstraction; Communication and Coordination Connection Within Framework: K–2.Computing Systems.Devices

控制结构(Control Structure), 被用来指定代码的执行顺序, 包括循环、事件处理、条件判断. 条件判断是指在不同条件下有选择地执行或者跳过代码指令.

  • 根据不同的情况需要选择不同类型的循环指令
  • “事件处理”的例子包括鼠标点击、在键盘上打字、对象之间的碰撞. 事件处理程序是指一组与特定事件相关联的代码指令(比如说鼠标点击不同按钮, 就触发不同程序)
  • “条件判断”相当于“决策”, 由一个“布尔条件”组成, 根据条件的评估结果是真还是假来决定采用哪个行动. 布尔逻辑和运算符 (比如AND、OR、NOT) 组合起来, 可以用于各种条件, 判断选择哪个合适的代码执行


# Grade 8 ( 11-14岁 ) 要掌握的程度

Programmers select and combine control structures, such as loops, event handlers, and conditionals, to create more complex program behavior.

Conditional statements can have varying levels of complexity, including compound and nested conditionals. Compound conditionals combine two or more conditions in a logical relationship, and nesting conditionals within one another allows the result of one conditional to lead to another being evaluated. An example of a nested conditional structure is deciding what to do based on the weather outside. If it is sunny outside, I will further decide if I want to ride my bike or go running, but if it is not sunny outside, I will decide whether to read a book or watch TV. Different types of control structures can be combined with one another, such as loops and conditionals. Different types of programming languages implement control structures in different ways. For example, functional programming languagesimplement repetition using recursive function calls instead of loops. At this level, understanding implementation in multiple languages is not essential.

Crosscutting Concept: Abstraction

程序员通过选择和组合控制结构(比如循环、事件处理、条件判断), 来创建能够解决复杂问题的程序.

条件判断可以有不同程度的复杂性, 比如使用复合和嵌套, 可以创建复杂的条件判断:

  • 复合条件判断, 是指在逻辑关系上结合了两个或者两个以上的条件判断语句
  • 嵌套条件判断, 是指允许一个条件判断的结果直接决定另一个条件是否被评估. 比如说, 根据外面的天气来决定做什么, 就是一个嵌套条件判断 -- 如果外面天气晴朗, 我将进一步决定是否要骑自行车或者去跑步; 如果外面没有阳光, 我将决定是看书还是看电视.

不同类型的控制结构也可以进行结合, 不如将循环和条件判断组合起来使用.

不同类型的编程语言使用不同的方式来表示控制结构. 比如, “函数式编程语言“使用递归函数调用来实现重复, 而不是使用循环来实现重复.

对于这个阶段的学生, 并不需要了解不同编程语言是如何实现控制结构的.


# Grade 12 ( 14-18岁 ) 要掌握的程度

Programmers consider tradeoffs related to implementation, readability, and program performance when selecting and combining control structures.

Implementation includes the choice of programming language, which affects the time and effort required to create a program. Readability refers to how clear the program is to other programmers and can be improved through documentation. The discussion of performance is limited to a theoretical understanding of execution time and storage requirements; a quantitative analysis is not expected. Control structures at this level may include conditional statements, loops, event handlers, and recursion. Recursion is a control technique in which a procedure calls itself and is appropriate when problems can be expressed in terms of smaller versions of themselves. Recursion is an optional concept at this level.

Crosscutting Concepts: Abstraction; System Relationships

程序员在选择和组合控制结构时, 要权衡写代码的方便性、代码的可读性和程序执行性能.

  • 写代码的方便性: 包括对编程语言的选择, 它直接影响到创建一个程序需要的时间和精力.
  • 代码的可读性: 指的是其他程序员能否轻易理解这段代码. 代码的可读性可以通过注释和说明文档来改善.
  • 程序执行性能: 对于这个阶段的学生, 对性能的讨论仅限于对执行时间和存储要求的定性理解, 并不需要进行定量分析.

学生对于控制结构的掌握需要包括条件语句、循环、事件处理和递归. 递归是一种特殊的控制技术, 在递归中, 程序会自己调用自己. 当问题可以用较小版本的程序来表达时, 选用递归是合适的. 注意, 对于这个阶段的学生, 递归是个可选的概念, 可以掌握, 也可以不掌握.


  1. “事件”: 是指计算机监测到的输入, 比如鼠标点击、光标移动、键盘被点击、麦克风接收到声音... “事件”通常用于触发计算机的操作 ↩︎

  2. “字面意思”: 是指计算机会根据代码原原本本的意思来理解, 而不会理解代码背后的思想和隐含的意义. 比如我们读书的时候, 需要总结文章的”中心思想“, 这就不是”字面意思“, 而是背后隐藏的含义 ↩︎