Block description

The If block evaluates the block(s) inside its head and executes the contents of the block based on whether the condition(s) evaluates to True or False.
This block can be used as both an If and an If-else block.

If functionality

• If the block(s) inside the head evaluates to TRUE,

  • blocks inside the IF section of the block are executed.
    • If the block(s) inside the head evaluates to FALSE,
  • blocks inside the IF section of the block are skipped from execution.

If-else functionality

• If the block(s) inside the head evaluates to TRUE,

  • blocks inside the IF section of the block are executed.
    • If the block(s) inside the head evaluates to FALSE,
  • blocks inside the ELSE section are executed.

App interface and usage

Number of conditions:

Here, you can set the number of conditions to be checked inside the If block.
You can check a single condition or two conditions.
If 1

Single condition:

You can choose Single to check 1 condition in the head of the block,
The block then appears as below:
If 1

Double condition:

You can choose Double to check 2 conditions in the head of the block,
If Double

Operator:

Here you can set the operator to be used while evaluating the combination of the conditions in the head of the block.
If Double Op

Else functionality:

The block’s functionality can be extended to an If else functionality by enabling the Else section of the block.
In case of a single condition, the block then appears as below:
If 2

In case of a double condition, the block then appears as below:
If 4

Guidelines

• A maximum of 2 conditions can be checked in a single If block.
• If two conditions are being checked, logical operators AND and OR can be used to evaluate their combination.

Examples

1.This project continuously monitors the on-board IR sensor from the time of upload till power-off or the next project is updated, and turns the buzzer on if the IR value exceeds 500 and turns it off when it is equal to or drops below 500. The state of the IR sensor is continuously monitored as the If block is housed inside a Loop infinitely block.
If Ex Main

Note: The below examples are code snippets to explain the working of the block. In this case, this code will be executed once and exactly at the time of uploading the code.
You will need to use this snippet inside a loop infinitely block if you want this code to run on the board for the entire duration that the board is on.

2.The below project snippet checks the value of the on-board Light sensor and turns the buzzer ON if it is greater than or equal to 666.
If Ex 1

3.The below project snippet checks if the value of the on-board IR sensor is less than 500. If this value is less than 500, it keeps the buzzer off and using the Else functionality, turns it ON if it is greater than or equal to 500
If Ex 1

4.The below project snippet checks for two conditions. If either the value of the on-board IR sensor is less than 500 OR motion is detected, the buzzer is turned ON.
If Ex 3

5.The below project snippet uses the block as an If-Else block and checks for two conditions. If both the value of the on-board IR sensor is less than 500 AND motion is detected, the buzzer is turned ON. If both of these conditions are false, the buzzer remains or is turned off.
If Ex 4

Also read:

Input blocks
Variables