Control#
Introduction#
The Control blocks in VEXcode VR 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
当开始 :: hat events
[Move forward for one second, then stop.]
驱动 [向前 v]
等待 (1) 秒
驱动停止
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. |
Example
当开始 :: hat events
[Move forward until a button is pressed, then stop.]
驱动 [向前 v]
等到 <[LeftBumper v] 按下了?>
驱动停止
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
当开始 :: hat events
[Move in a square path.]
重复 [4]
驱动 [向前 v] [150] [毫米 v] ▶
[右 v] 转 [90] 度 ▶
结束
forever#
The forever block keeps running the blocks inside it again and again without stopping.
永久循环
结束
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
当开始 :: hat events
[Move in a square path forever.]
永久循环
驱动 [向前 v] [150] [毫米 v] ▶
[右 v] 转 [90] 度 ▶
结束
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
当开始 :: hat events
[Move the pen until the bumper is pressed.]
驱动 [向前 v]
重复直到 <[LeftBumper v] 按下了?>
移动笔 [向下 v]
等待 (0.5) 秒
移动笔 [向上 v]
等待 (0.5) 秒
结束
等待 (0.5) 秒
驱动停止
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
当开始 :: hat events
[Display a message while moving.]
驱动 [向前 v] [300] [毫米 v] ◀ 并且不等待
当 <驱动进行中?>
打印 [Moving...] ▶
等待 (0.1) 秒
清除所有行
结束
打印 [Done!] ▶
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
当开始 :: hat events
[Turn in a circle if the bumper is pressed.]
驱动 [向前 v]
永久循环
如果 <[LeftBumper v] 按下了?> 那么
驱动 [反 v] (200) [毫米 v] ▶
[右 v] 转 (360) 度 ▶
结束
驱动停止
结束
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
当开始 :: hat events
[If bumper pressed, reverse and turn right.]
永久循环
如果 <[LeftBumper v] 按下了?> 那么
驱动 [反 v] (100) [毫米 v] ▶
[右 v] 转 (90) 度 ▶
否则
驱动 [向前 v]
结束
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
当开始 :: hat events
[Turn right if the an Eye Sensor detects red, left if it detects green, and continue driving if anything else.]
永久循环
如果 <[FrontEye v] 测得 [红色 v]?> 那么
[右 v] 转 (90) 度 ▶
否则如果 <[FrontEye v] 测得 [绿色 v]?> 那么
[左 v] 转 (90) 度 ▶
否则
驱动 [向前 v]
结束
结束
break#
The break block exits a loop immediately.
退出循环
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
当开始 :: hat events
[Stop turning after a button is pressed.]
永久循环
驱动 [向前 v]
如果 <[LeftBumper v] 按下了?> 那么
退出循环
结束
结束
驱动停止
stop project#
The stop project block ends a running project.
停止程序
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
当开始 :: hat events
[Stop the project entirely after a button is pressed.]
永久循环
驱动 [向前 v]
如果 <[LeftBumper v] 按下了?> 那么
停止程序
结束
结束