控制#
介绍#
The Control blocks in VEXcode EXP manage the flow of a project by handling loops, conditions, and delaying blocks from running.
A loop is when a computer repeats the same step or group of steps over and over until it is told to stop. A condition is a rule the computer checks to decide what to do next. For example, a robot can move forward if a sensor detects an object.
以下是可用模块列表:
wait – Pauses blocks from running for a specific duration.
wait until – Pauses blocks from running until a specified condition is met.
repeat – Repeats a set of blocks a specific number of times.
forever – Repeats a set of blocks indefinitely.
repeat until – Repeats a set of blocks until a condition is met.
while – Repeats a set of blocks while a condition remains true.
if – Runs a set of blocks if a condition is true.
if / else – 如果条件为真,则运行一组代码块;否则,运行另一组代码块。
if / else if / else – 根据多个条件运行不同的代码块集。
break – 立即退出 repeat、forever、repeat until 或 while 循环。
stop project – Ends the project.
等待#
The wait stack block pauses blocks from running for a specific amount of time before moving to the next block.
等待 (1) 秒
参数 |
描述 |
|---|---|
时间 |
The amount of time to wait, as a positive whole number or decimal in seconds. |
例子
当开始
[Move forward for one second, then stop.]
驱动 [向前 v]
等待 (1) 秒
驱动停止
等到#
The wait until stack block pauses blocks from running until a specified condition is met before moving to the next block.
等到 <>
参数 |
描述 |
|---|---|
状况 |
进入下一模块之前必须满足的条件。 |
例子
当开始
[Move forward until the ◀ button is pressed, then stop.]
驱动 [向前 v]
等到 <Brain [ 键按下了?>
驱动停止
重复#
The repeat C block runs the blocks inside it a set number of times.
重复 [10]
结束
参数 |
描述 |
|---|---|
时代 |
一个整数,用于设置重复块运行的次数。 |
例子
当开始
[Move in a square path.]
重复 [4]
驱动 [向前 v] [150] [毫米 v] ▶
[右 v] 转 [90] 度 ▶
结束
永远#
The forever C block keeps running the blocks inside it again and again without stopping.
永久循环
结束
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Move in a square path forever.]
永久循环
驱动 [向前 v] [150] [毫米 v] ▶
[右 v] 转 [90] 度 ▶
结束
重复直到#
The repeat until C block runs the blocks inside it repeatedly while the specified condition is not met.
重复直到 <>
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked before each loop. If it is False, the blocks continue repeating. If it is True, the loop will stop. |
例子
当开始
[Turn until the screen is pressed.]
重复直到 <屏幕按下了?>
[右 v] 转
结束
驱动停止
尽管#
The while C block runs the blocks inside repeatedly while the specified condition is met.
当 <>
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked before each loop. If it is True, the blocks continue repeating. If it is False, the loop will stop. |
例子
当开始
[Display the time for one minute.]
当 <(计时器秒数) [math_less_than v] [60]>
清屏
在屏幕上设定光标至 [1] 行 [1] 列
在屏幕上打印 (计时器秒数)▶
如果#
The if C block runs the blocks inside if the condition is True.
如果 <> 那么
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked when the statement runs. If it is True, the blocks inside the if block will run. If it is False, the blocks are skipped over. |
例子
当开始
[Turn in a circle if the screen is pressed.]
永久循环
如果 <屏幕按下了?> 那么
[右 v] 转 [360] 度 ▶
结束
驱动停止
结束
如果/否则#
The if / else C block determines which set of blocks runs based on whether the condition is True or False.
如果 <> 那么
否则
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked when the statement runs. If it is True, the blocks inside the if block will run. If it is False, it will runs the blocks inside the else block. |
例子
当开始
[Display a message if the screen is being pressed.]
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
如果 <屏幕按下了?> 那么
在屏幕上打印 [Pressed!]▶
否则
在屏幕上打印 [Not pressed!]▶
结束
如果/否则如果/否则#
The if / else if / else expandable C block selects which set of blocks runs based on conditions:
if runs its block of code if the condition evaluates as True.
else if checks additional conditions only if all previous conditions evaluated as False. Multiple else if statements can be used.
else runs its block of code only if none of the previous conditions evaluated as True.
如果 <> 那么
否则如果 <> 那么
否则
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked when the statement runs. The first condition that is True runs that set of blocks. If all conditions evaluate as False, the blocks inside the else block will run. |
例子
当开始
[Move the robot based on the Controller button is being pressed.]
永久循环
如果 <[Controller 1 v] [ 按下?> 那么
[右 v] 转
否则如果 <[Controller 1 v] [ 按下?> 那么
[左 v] 转
否则
驱动停止
结束
休息#
The break stack block exits a loop immediately. This block can be used inside repeat, repeat until, while, and forever blocks. Break is useful when a loop needs to stop early based on something that happens during the project, like a button being pressed or a sensor detecting an object.
退出循环
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Stop turning after the screen is pressed.]
永久循环
[右 v] 转
如果 <屏幕按下了?> 那么
退出循环
结束
结束
驱动停止
停止项目#
The stop project stack block ends a running project.
停止程序
参数 |
描述 |
|---|---|
此代码块没有参数。 |
例子
当开始
[Stop the project entirely after the screen is pressed.]
永久循环
[右 v] 转
如果 <屏幕按下了?> 那么
停止程序
结束
结束