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.

wait stack block#
esperar (1) segundos

Parameters

Description

time

The amount of time to wait, as a positive integer or decimal in seconds.

Example

When started, moves forward for one second, then stops all movement.#
cuando empezó
[Move to the left, then the right after one second.]
incrementar la posición [brazo v] en x:[100] y:[0] z:[0] [mm v] ▶
esperar (1) segundos
incrementar la posición [brazo v] en x:[-100] y:[0] z:[0] [mm v] ▶

wait until#

The wait until block pauses execution until a specified condition is met before proceeding to the next block.

wait until stack block#
esperar hasta <>

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.

repeat c block#
repetir [10]
fin

Parameters

Description

times

A whole number that sets how many times the repeat block runs.

Example

cuando empezó
[Move in a square pattern.]
repetir [4]
incrementar la posición [brazo v] en x:[2] y:[0] z:[0] [pulgadas v] ▶
incrementar la posición [brazo v] en x:[0] y:[2] z:[0] [pulgadas v] ▶
incrementar la posición [brazo v] en x:[-2] y:[0] z:[0] [pulgadas v] ▶
incrementar la posición [brazo v] en x:[0] y:[2] z:[0] [pulgadas v] ▶
fin

forever#

The forever block keeps running the blocks inside it again and again without stopping.

forever c block#
para siempre
fin

Parameters

Description

This block has no parameters.

Example

When started, continuously moves in a square path by moving forward 50 mm and turning right 90 degrees in an infinite loop.#
cuando empezó
[Move in a square path forever.]
para siempre
incrementar la posición [brazo v] en x:[2] y:[0] z:[0] [pulgadas v] ▶
incrementar la posición [brazo v] en x:[0] y:[2] z:[0] [pulgadas v] ▶
incrementar la posición [brazo v] en x:[-2] y:[0] z:[0] [pulgadas v] ▶
incrementar la posición [brazo v] en x:[0] y:[2] z:[0] [pulgadas v] ▶
fin

repeat until#

The repeat until block executes the enclosed blocks repeatedly while the condition evaluates as False.

repeat until block#
repetir hasta <>
fin

Parameters

Description

condition

An expression or variable that is evaluated before each iteration. If it evaluates as:

  • False - The loop continues
  • True - The loop stops

Example

When started, keeps all LEDs red until the screen is pressed, then turns them off.#
cuando empezó
[Increment along the x-axis until it's no longer possible.]
repetir hasta <no <[brazo v] incremento de posición por x:[100] y:[0] z:[0] [mm v]?>>
incrementar la posición [brazo v] en x:[100] y:[0] z:[0] [mm v] ▶
fin
Establecer [brazo v] para controlar la detención

while#

The while block executes the enclosed blocks repeatedly while the condition evaluates as True.

while c block#
mientras <>
fin

Parameters

Description

condition

An expression or variable that is evaluated before each iteration. If it evaluates as:

  • True - The loop continues
  • False - The loop stops

Example

A stack of blocks that begins with a when started block, followed by a comment block reading Display the time after 2 seconds have passed. A wait until block pauses execution until the timer reaches or exceeds two seconds. Once this condition is met, a print block displays the timer value on the screen.#
cuando empezó
[Display the 6-Axis Arm's position as it moves.]
mover [brazo v] a la posición x:(-100) y:(200) z:(100) [mm v] ◀ y no esperes
mientras <no <[brazo v] ya termino de moverme?>>
imprimir ([brazo v] posición [y v] en [mm v]) en la consola ◀ y coloque el cursor en la siguiente fila
esperar [0.25] segundos

if#

The if block executes the enclosed block of code if the condition evaluates as True.

if block#
si <> entonces
fin

Parameters

Description

condition

An expression or variable that is evaluated when the statement runs. If it evaluates as:

  • True - The code inside the if block executes
  • False - The block is skipped

Example

cuando empezó
[Check if the 6-Axis Arm can move to a position.]
si <no <[arm v] move to position x:[0] y:[0] z:[0] [mm v] ?>> entonces
imprimir [The 6-Axis Arm can't move to this position.] ◀ y coloque el cursor en la siguiente fila

if / else#

The if / else block determines which enclosed block of code runs based on whether the condition evaluates as True or False.

if then else block#
si <> entonces
demás
fin

Parameters

Description

condition

An expression or variable that is evaluated when the statement runs. If it evaluates as:

  • True - The code inside the if block executes
  • False - The code inside the else block executes instead

Example

cuando empezó
[Check if the 6-Axis Arm can or can't move to a position.]
si <no <[arm v] move to position x:[100] y:[100] z:[100] [mm v] ?>> entonces
imprimir [The 6-Axis Arm can't move to this position.] en la consola ◀ y coloque el cursor en la siguiente fila
demás
imprimir [The 6-Axis Arm can move to this position.] en la consola ◀ y coloque el cursor en la siguiente fila

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.

if else if else block#
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:

  • True - Determines which block of code executes
  • False - If none are True, the else block of code runs

Example

cuando empezó
[Move until the 6-Axis Arm is at the corner of the tile.]
si <[brazo v] incremento de posición por x:[50] y:[0] z:[0] [mm v]?> entonces
incrementar la posición [arm] en x:[50] y:[0] z:[0] [mm v] ▶
de lo contrario si <[brazo v] incremento de posición por x:[0] y:[50] z:[0] [mm v]?> entonces
incrementar la posición [arm] en x:[0] y:[50] z:[0] [mm v] ▶
demás
imprimir [The 6-Axis Arm has reached the corner.] en la consola ◀ y coloque el cursor en la siguiente fila

break#

The break block exits a loop immediately.

break stack block#
romper

Parameters

Description

This block has no parameters.

stop project#

The stop project block ends a running project.

stop project block#
detener el proyecto

Parameters

Description

This block has no parameters.