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.
esperar (1) segundos
Parameters |
Description |
|---|---|
time |
The amount of time to wait, as a positive integer or decimal in seconds. |
Example
cuando empezó :: hat events
[Move forward for one second, then stop.]
unidad [adelante v]
esperar (1) segundos
deja de conducir
wait until#
The wait until block pauses execution until a specified condition is met before proceeding to the next block.
esperar hasta <>
Parameters |
Description |
|---|---|
condition |
The condition that must be met before moving on to the next block. |
Example
cuando empezó :: hat events
[Move forward until a button is pressed, then stop.]
unidad [adelante v]
esperar hasta <[LeftBumper v] presionado?>
deja de conducir
repeat#
The repeat block runs the blocks inside it a set number of times.
repetir [10]
fin
Parameters |
Description |
|---|---|
times |
A whole number that sets how many times the repeat block runs. |
Example
cuando empezó :: hat events
[Move in a square path.]
repetir [4]
unidad [adelante v] para [150] [mm v] ▶
girar [derecha v] por [90] grado ▶
fin
forever#
The forever block keeps running the blocks inside it again and again without stopping.
para siempre
fin
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
cuando empezó :: hat events
[Move in a square path forever.]
para siempre
unidad [adelante v] para [150] [mm v] ▶
girar [derecha v] por [90] grado ▶
fin
repeat until#
The repeat until block executes the enclosed blocks repeatedly while the condition evaluates as False.
repetir hasta <>
fin
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated before each iteration. If it evaluates as:
|
Example
cuando empezó :: hat events
[Move the pen until the bumper is pressed.]
unidad [adelante v]
repetir hasta <[LeftBumper v] presionado?>
mover pluma [abajo v]
esperar (0.5) segundos
mover pluma [arriba v]
esperar (0.5) segundos
fin
esperar (0.5) segundos
deja de conducir
while#
The while block executes the enclosed blocks repeatedly while the condition evaluates as True.
mientras <>
fin
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated before each iteration. If it evaluates as:
|
Example
cuando empezó :: hat events
[Display a message while moving.]
unidad [adelante v] para [300] [mm v] ◀ y no esperes
mientras <¿La unidad se está moviendo?>
imprimir [Moving...] ▶
esperar (0.1) segundos
borrar todas las filas
fin
imprimir [Done!] ▶
if#
The if block executes the enclosed block of code if the condition evaluates as True.
si <> entonces
fin
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. If it evaluates as:
|
Example
cuando empezó :: hat events
[Turn in a circle if the bumper is pressed.]
unidad [adelante v]
para siempre
si <[LeftBumper v] presionado?> entonces
unidad [atrás v] para (200) [mm v] ▶
girar [derecha v] por (360) grado ▶
fin
deja de conducir
fin
if / else#
The if / else block determines which enclosed block of code runs based on whether the condition evaluates as True or False.
si <> entonces
demás
fin
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. If it evaluates as:
|
Example
cuando empezó :: hat events
[If bumper pressed, reverse and turn right.]
para siempre
si <[LeftBumper v] presionado?> entonces
unidad [atrás v] para (100) [mm v] ▶
girar [derecha v] por (90) grado ▶
demás
unidad [adelante v]
fin
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.
si <> entonces
de lo contrario si <> entonces
demás
fin
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. The first condition that evaluates as:
|
Example
cuando empezó :: hat events
[Turn right if the an Eye Sensor detects red, left if it detects green, and continue driving if anything else.]
para siempre
si <[FrontEye v] detecta [rojo v]?> entonces
girar [derecha v] por (90) grado ▶
de lo contrario si <[FrontEye v] detecta [verde v]?> entonces
girar [izquierda v] por (90) grado ▶
demás
unidad [adelante v]
fin
fin
break#
The break block exits a loop immediately.
romper
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
cuando empezó :: hat events
[Stop turning after a button is pressed.]
para siempre
unidad [adelante v]
si <[LeftBumper v] presionado?> entonces
romper
fin
fin
deja de conducir
stop project#
The stop project block ends a running project.
detener el proyecto
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
cuando empezó :: hat events
[Stop the project entirely after a button is pressed.]
para siempre
unidad [adelante v]
si <[LeftBumper v] presionado?> entonces
detener el proyecto
fin
fin