Control#
Introduction#
The Control blocks in VEXcode GO 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 (1) seconds
Parameters |
Description |
|---|---|
time |
The amount of time to wait, as a positive integer or decimal in seconds. |
Example
when started :: hat events
[Build Used: Code Base 2.0]
[Drive forward then stop.]
drive [forward v]
wait (2) seconds
stop driving
wait until#
The wait until block pauses execution until a specified condition is met before proceeding to the next block.
wait until <>
Parameters |
Description |
|---|---|
condition |
The condition that must be met before moving on to the next block. |
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Drive forward when the LED Bumper is pressed.]
wait until <[bumper v] pressed?>
drive [forward v] for [200] [mm v] ▶
repeat#
The repeat block runs the blocks inside it a set number of times.
repeat [10]
end
Parameters |
Description |
|---|---|
times |
A whole number that sets how many times the repeat block runs. |
Example
when started :: hat events
[Build Used: Code Base 2.0]
[Drive in a square pattern.]
repeat [4]
drive [forward v] for [200] [mm v] ▶
turn [right v] for [90] degrees ▶
forever#
The forever block keeps running the blocks inside it again and again without stopping.
forever
end
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Build Used: Code Base 2.0 - Eye Forward]
[Blink LED light in a pattern.]
forever
set [bumper v] to [green v]
wait [0.5] seconds
set [bumper v] to [off v]
wait [0.5] seconds
repeat until#
The repeat until block executes the enclosed blocks repeatedly while the condition evaluates as False.
repeat until <>
end
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated before each iteration. If it evaluates as:
|
Example
when started :: hat events
[Build Used: Code Base 2.0 - Eye Forward]
[Blink LED light until the LED Bumper is pressed.]
repeat until <[bumper v] pressed?>
set [bumper v] to [green v]
wait [0.5] seconds
set [bumper v] to [off v]
wait [0.5] seconds
while#
The while block executes the enclosed blocks repeatedly while the condition evaluates as True.
while <>
end
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated before each iteration. If it evaluates as:
|
Example
when started :: hat events
[Build Used: Code Base 2.0]
[Turn the robot around.]
while <(drive heading in degrees) [math_less_than v] [180] >
turn [right v]
end
stop driving
if#
The if block executes the enclosed block of code if the condition evaluates as True.
if <> then
end
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. If it evaluates as:
|
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Drive forward whenever the LED Bumper is pressed.]
forever
if <[bumper v] pressed?> then
drive [forward v] for [200] [mm v] ▶
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
end
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. If it evaluates as:
|
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Drive forward if there is no an object in the way.]
forever
if <eye found an object?> then
stop driving
else
drive [forward v] for [200] [mm 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.
if <> then
else if <> then
else
end
Parameters |
Description |
|---|---|
condition |
An expression or variable that is evaluated when the statement runs. The first condition that evaluates as:
|
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Turn right for red, left for green.]
forever
if <eye detects [red v] ?> then
turn [right v]
else if <eye detects [green v] ?> then
turn [left v]
else
stop driving
break#
The break block exits a loop immediately.
break
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Flash the LED until the LED Bumper is pressed.]
forever
set [bumper v] to [green v]
wait [0.5] seconds
set [bumper v] to [red v]
wait [0.5] seconds
if <[bumper v] pressed?> then
break
stop project#
The stop project block ends a running project.
stop project
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Stop the project when the LED Bumper is pressed.]
forever
drive [forward v] for [100] [mm v] ▶
if <[bumper v] pressed?> then
stop project