If Then Blocks#

If Then Blocks

This tutorial covers how to use if/else blocks to make your robot check a condition and decide which blocks to run. By the end, you’ll know how to set up a condition and control what happens when it’s true or false.

Drag a Boolean block into the empty condition slot in the if then branch.

A controller pressed Boolean block being dragged into the empty condition slot of an if/else block.

All Boolean blocks are hexagon-shaped and have a question mark in their name, such as the controller pressed? block.

An if/else block with a controller R up pressed Boolean block, with the Boolean block highlighted.

If the condition is true, the blocks inside the if then branch will run.

An if/else block with a controller R up pressed Boolean block and a drive forward block, with the drive forward block highlighted.

If the condition is false, the blocks inside the else branch will run.

An if/else block with a controller R up pressed Boolean block, a drive forward block, and a stop driving block, with the stop driving block highlighted.

An if/else block only checks its condition once. If you want the condition to be checked repeatedly, put the if/else block inside a looping block, like forever.

An if/else block nested inside a forever block.#
για πάντα
αν <Χειριστήριο [R ▲ v] πατημένο;> τότε
κίνηση [εμπρός v]
αλλιώς
διακοπή κίνησης
τέλος
τέλος

The if block is only the if then branch. If the condition isn’t true, nothing will happen.

The if block.#
αν <Χειριστήριο [R ▲ v] πατημένο;> τότε
κίνηση [εμπρός v]
τέλος

The if / else if / else block can be used to test multiple conditions one after another. It can be expanded to test as many conditions as needed.

An if/else if/else block, testing all three Brain buttons.#
αν <Κουμπί Brain [▲ v] πατημένο;> τότε
στροφή [αριστερά v] για (90) μοίρες ▶
αλλιώς αν <Κουμπί Brain [▼ v] πατημένο;> τότε
στροφή [δεξιά v] για (90) μοίρες ▶
αλλιώς αν <Κουμπί Brain [Έλεγχος v] πατημένο;> τότε
διακοπή κίνησης
αλλιώς
κίνηση [εμπρός v]
τέλος