Control#

Wait#

The Wait block is used to wait for a specific amount of time before moving to the next block.

  wait (1) seconds

Choose an amount of time to wait.

The Wait block can accept decimals, integers, or numeric blocks.

In this example, the 123 Robot will drive forward for 2 seconds, then stop.

  when started :: hat events
  drive [forward v]
  wait (2) seconds
  stop driving

Repeat#

The Repeat C block is used to repeat the blocks contained inside for a set number of times.

  repeat (10)
  end

First enter a value to indicate how many times the stack will repeat the blocks contained inside.

The Repeat C block can accept integers or numeric blocks.

C blocks can also be put inside of each other. This concept is called nesting which can help save time when coding different behaviors.

In this example, the 123 Robot will drive forward for 30 millimeters and turn right by 90 degrees 4 times in a row to make a square.

  when started :: hat events
  repeat (4)
  drive [forward v] for (30) [mm v]
  turn [right v] for (90) degrees
  end

Forever#

The Forever C block is used to repeat any blocks contained inside forever.

  forever 
  end

Place blocks in a Forever C block to have those actions repeat forever.

You can exit a Forever C block by placing a break block inside.

C blocks can also be put inside of each other. This concept is called nesting which can help save time when coding different behaviors.

In this example, the Forever block is used to continuously check if the Sound button has been pressed as the 123 Robot drives forward. If the button is pressed, the 123 Robot will stop moving and will break out of the Forever block so it stops checking if the Sound button is pressed.

A visual coding block sequence that begins with a yellow 'when started' block. Below it is a blue 'drive forward' block, followed by a yellow 'forever' loop block, indicating that the enclosed actions will be repeated indefinitely. Inside the loop, there is a gray block with the instruction 'Check if the sound button is pressed.' This is followed by a yellow 'if-then' block containing a condition with a blue, diamond-shaped block that checks if the sound button is pressed. If the button is pressed, the sequence triggers the actions: a blue 'stop driving' block and a yellow 'break' block, which exits the loop and stops further checks.

If then#

The If then C block is used to run the blocks inside, if the Boolean condition reports True.

  if <> then
  end

The If then C block will only check the Boolean condition once.

If the Boolean condition reports True, the blocks inside of the C block will run.

If the Boolean condition reports False, the blocks inside of the C block will be skipped.

The If then C block can accept hexagonal (six-sided) shaped blocks as its condition.

In this example, the Forever block is used to continuously check if the Sound button has been pressed as the 123 Robot drives forward. If the button is pressed, the 123 Robot will stop moving and will break out of the Forever block so it stops checking if the Sound button is pressed.

A visual coding block sequence that begins with a yellow 'when started' block. Below it is a blue 'drive forward' block, followed by a yellow 'forever' loop block, indicating that the enclosed actions will be repeated indefinitely. Inside the loop, there is a gray block with the instruction 'Check if the sound button is pressed.' This is followed by a yellow 'if-then' block containing a condition with a blue, diamond-shaped block that checks if the sound button is pressed. If the button is pressed, the sequence triggers the actions: a blue 'stop driving' block and a yellow 'break' block, which exits the loop and stops further checks.

If then else#

The If then else C block is used to run the blocks inside the first or second parts of the if then else, based on the Boolean value reported.

  if <> then
  else
  end

The If then else C block will only check the Boolean condition once.

If the Boolean condition reports True, the blocks inside of the if section will be run.

If the Boolean condition reports False, the blocks inside of the else section will be run.

The If then else C block can accept hexagonal (six-sided) shaped blocks as its condition.

In this example, the If then else block is continuously checked to see if the Eye Sensor detects the color red. If the Eye Sensor detects the color red, the 123 Robot will drive forward. If the Eye Sensor doesn’t detect the color red, the 123 Robot will turn towards the right.

  when started :: hat events
  forever
  if<eye detects [red v]?> then
  drive [forward v]
  else
  turn [right v]

If then else if then else#

The If then else if then else C block is used to run the blocks inside the first set of internal blocks in the If then else if then else C block where the condition returns True.

  if <> then
  else if <> then
  else
  end

The If then else if then else C block will only check the Boolean condition once.

If the Boolean condition reports True, the blocks inside the if section will run.

If the Boolean condition reports False, the If then else if then else C block will check the first of the else if lines. For each else if line, the block will check if the Boolean condition is reports True. If it is true, the internal blocks directly under that line will run before continuing on to the next block under the If then else if then else C block.

If all the Boolean conditions for the else if lines report False, the blocks inside of the else section will be run.

The If then else if then else C block can accept hexagonal (six-sided) shaped blocks as its condition.

To add another else if condition, click on the + on the else line. This will add a new else if condition to the bottom of the current list.

To remove an else if condition, click on the - on the else line. This will remove the last else if condition line, but will not delete any used blocks in the condition.

In this example, the If then else if then else block is checked continuously to see if the Eye Sensor has detected the color red, then green. If the Eye Sensor detects either the colors red or green, the 123 Robot will drive forward. If the Eye Sensor does not detect red or green, the 123 Robot will turn towards the right.

  when started :: hat events
  forever
  if <eye detects [red v] ?> then
  drive [forward v]
  else if <eye detects [green v]? > then
  drive [forward v]
  else
  turn [right v]

Wait until#

The Wait until block is used to wait for a Boolean block to report True before moving to the next block.

  wait until <>

The Wait until block will repeatedly check a Boolean reporter block and will not move to the next block until the Boolean report block reports True.

The Wait until Boolean block can accept hexagonal (six-sided) shaped blocks.

In this example, the 123 Robot will only start moving when the Sound button is pressed.

A visual coding block sequence that begins with a yellow 'when started' block. Below it is a yellow 'wait until' block, which pauses the execution of the program until the specified condition is met. The condition, placed inside a blue diamond-shaped block, checks if a button is pressed. Once the button is pressed, the sequence triggers the action 'drive forward' using a blue block.

Repeat until#

The Repeat until C block is used to repeat the blocks inside until the Boolean condition reports True.

  repeat until <>

The Repeat until C block will only check the Boolean condition at the beginning of each loop.

If the Boolean condition reports False, the blocks inside of the block will run.

If the Boolean condition reports True, the blocks inside of the block will be skipped.

The Repeat until C block can accept hexagonal (six-sided) shaped blocks as its condition.

In this example, the 123 Robot will drive forward until it detects a crash.

  when started :: hat events
  repeat until <detected crash?>
  drive [forward v] for (1) [steps v]

While#

The While C block is used to repeat the blocks inside while the Boolean condition reports True.

  while <>

The While C block will only check the Boolean condition at the beginning of each loop.

If the Boolean condition is reports True, the blocks inside of the block will run.

If the Boolean condition is reports False, the blocks inside of the block will be skipped.

The While C block can accept hexagonal (six-sided) shaped blocks as its condition.

In this example, the 123 Robot will drive forward while the Brain’s timer is less than 2 (seconds). After 2 seconds, the 123 Robot will stop driving.

  when started :: hat events
  [Drive forward when the timer reads less than 2 (seconds).]
  while <(timer in seconds) < (2)>
  drive [forward v]
  end
  stop driving

Break#

The Break block is used to exit a repeating loop immediately.

  break

When added to a repeating C block, the Break block will exit the loop it is currently in.

In this example, the Forever block is used to continuously check if the Sound button has been pressed as the 123 Robot drives forward. If the button is pressed, the 123 Robot will stop moving and will break out of the Forever block so it stops checking if the Sound button is pressed.

A sequence of coding blocks in a vertical stack. It starts with a yellow 'when started' block, followed by a blue 'drive forward' block, and an orange 'forever' loop. Inside the loop, there’s a gray comment block that reads 'Check if the sound button is pressed.' Below that is an orange 'if' block that checks if the sound button is pressed, with a blue 'stop driving' block and a yellow 'break' block nested inside. This structure is used to keep driving forward until the sound button is pressed, then stop driving and exit the loop.

Stop project#

The Stop project block is used to stop a running project

  stop project

In this example, the 123 Robot will drive forward for two seconds before the project stops.

  when started :: hat events
  drive [forward v]
  wait (2) seconds
  stop project