Control#
Introduction#
The Control blocks in VEXcode manage the flow of a project by handling loops, conditions, delays, and stopping execution.
Below is a list of available blocks:
wait – Pauses execution for a specific duration.
wait until – Pauses execution until a specified condition is met.
repeat – Repeats enclosed blocks a specific number of times.
forever – Repeats enclosed blocks indefinitely.
repeat until – Repeats enclosed blocks until a condition is met.
while – Repeats enclosed blocks while a condition remains true.
if – Runs enclosed blocks if a condition is true.
if / else – Runs one set of blocks if a condition is true, otherwise runs another.
if / else if / else – Runs different sets of blocks depending on multiple conditions.
break – Exits a repeat, forever, repeat until, or while loop immediately.
stop project – Ends the execution of the project.
wait#
The wait block pauses for a specific amount of time before moving to the next block.
等待 (1) 秒
Parameters |
Description |
|---|---|
time |
The amount of time to wait, as a positive integer or decimal in seconds. |
Example
当开始
[Move to the left, then the right after one second.]
[手臂 v] 位置递增x:[100] y:[0] z:[0] [毫米 v] ▶
等待 (1) 秒
[手臂 v] 位置递增x:[-100] y:[0] z:[0] [毫米 v] ▶
wait until#
The wait until block pauses execution until a specified condition is met before proceeding to the next block.
等到 <>
Parameters |
Description |
|---|---|
condition |
The condition that must be met before moving on to the next block. |
repeat#
The repeat block runs the blocks inside it a set number of times.
重复 [10]
结束
Parameters |
Description |
|---|---|
times |
A whole number that sets how many times the repeat block runs. |
Example
当开始
[Move in a square pattern.]
重复 [4]
[手臂 v] 位置递增x:[2] y:[0] z:[0] [英寸 v] ▶
[手臂 v] 位置递增x:[0] y:[2] z:[0] [英寸 v] ▶
[手臂 v] 位置递增x:[-2] y:[0] z:[0] [英寸 v] ▶
[手臂 v] 位置递增x:[0] y:[2] z:[0] [英寸 v] ▶
结束
forever#
The forever block keeps running the blocks inside it again and again without stopping.
永久循环
结束
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
当开始
[Move in a square path forever.]
永久循环
[手臂 v] 位置递增x:[2] y:[0] z:[0] [英寸 v] ▶
[手臂 v] 位置递增x:[0] y:[2] z:[0] [英寸 v] ▶
[手臂 v] 位置递增x:[-2] y:[0] z:[0] [英寸 v] ▶
[手臂 v] 位置递增x:[0] y:[2] z:[0] [英寸 v] ▶
结束
repeat until#
The repeat until block executes the enclosed blocks repeatedly while the condition evaluates as False.
重复直到 <>
结束
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated before each iteration. If it evaluates as:
|
Example
当开始
[Increment along the x-axis until it's no longer possible.]
重复直到 <非 <[手臂 v] 位置增加x:[100] y:[0] z:[0] [毫米 v]?>>
[手臂 v] 位置递增x:[100] y:[0] z:[0] [毫米 v] ▶
结束
设定 [手臂 v] 停用
while#
The while block executes the enclosed blocks repeatedly while the condition evaluates as True.
当 <>
结束
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated before each iteration. If it evaluates as:
|
Example
当开始
[Display the 6-Axis Arm's position as it moves.]
移动 [手臂 v] 到位置x:(-100) y:(200) z:(100) [毫米 v] ◀ 并且不等待
当 <非 <[手臂 v] 已结束?>>
在控制台上打印 ([手臂 v] [y v] 位置 [毫米 v])◀ 并设定光标为下一行
等待 [0.25] 秒
if#
The if block executes the enclosed block of code if the condition evaluates as True.
如果 <> 那么
结束
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. If it evaluates as:
|
Example
当开始
[Check if the 6-Axis Arm can move to a position.]
如果 <非 <[arm v] move to position x:[0] y:[0] z:[0] [mm v] ?>> 那么
打印 [The 6-Axis Arm can't move to this position.] ◀ 并设定光标为下一行
if / else#
The if / else block determines which enclosed block of code runs based on whether the condition evaluates as True or False.
如果 <> 那么
否则
结束
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. If it evaluates as:
|
Example
当开始
[Check if the 6-Axis Arm can or can't move to a position.]
如果 <非 <[arm v] move to position x:[100] y:[100] z:[100] [mm v] ?>> 那么
在控制台上打印 [The 6-Axis Arm can't move to this position.]◀ 并设定光标为下一行
否则
在控制台上打印 [The 6-Axis Arm can move to this position.]◀ 并设定光标为下一行
if / else if / else#
The if / else if / else block structure selects which enclosed block of code 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.
如果 <> 那么
否则如果 <> 那么
否则
结束
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. The first condition that evaluates as:
|
Example
当开始
[Move until the 6-Axis Arm is at the corner of the tile.]
如果 <[手臂 v] 位置增加x:[50] y:[0] z:[0] [毫米 v]?> 那么
[arm] 位置递增x:[50] y:[0] z:[0] [毫米 v] ▶
否则如果 <[手臂 v] 位置增加x:[0] y:[50] z:[0] [毫米 v]?> 那么
[arm] 位置递增x:[0] y:[50] z:[0] [毫米 v] ▶
否则
在控制台上打印 [The 6-Axis Arm has reached the corner.]◀ 并设定光标为下一行
break#
The break block exits a loop immediately.
退出循环
Parameters |
Description |
|---|---|
This block has no parameters. |
stop project#
The stop project block ends a running project.
停止程序
Parameters |
Description |
|---|---|
This block has no parameters. |