Operator (Part 2)

Operators: are programming blocks used to perform mathematical operations or logical comparisons.

These blocks allow you to manipulate numbers and make decisions based on conditions.

Such as:

operators

Logical operators:

or-and-green

-> Logical operators are used to create more complex conditions.

-> They are especially useful in decision-making and branching structures, allowing your robot to make intelligent choices based on sensor inputs or other conditions.

"AND" operator

And-operator

For example:

-> Is it true that fruit AND fried chicken are healthy?

No. So, this is false

-> Is it true that apple AND strawberry are healthy?

Yes. So, this is true

And-example

"AND" operator combines two conditions and returns true only if both conditions are true. It's represented by the symbol "&&."

For example:

Condition 1: Touch sensor is pressed.

Condition 2: Color sensor detects red.

Combined Condition: Touch sensor is pressed && Color sensor detects red.

Repeat Until "And" Operator

4-and-red-15cm

1- Repeat [Robot move backward at the speed of 50%]

2- Until [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"]

3- Stop moving

False:

false-and
4-and-red-15cm-copy-2

-> Robot did not stop because the condition it's not met. So, it's false.

-> Because ONLY ultrasonic sensor "less than 15cm" BUT not Color sensor.

BOTH condition have to be fulfill in order to meet the condition.

True:

true-and
4-and-red-15cm

-> [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] is detected. Condition it's met.

-> Robot Stop moving

If-Else "And" Operator

6-And-if-else-red-15cm

IF

1- If [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] condition is met

2- Robot move FORWARD at the speed of 50%

ELSE

1- If [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] condition NOT met

2- Robot move BACKWARD at the speed of 50%

False:

false-and-ifElse
6-And-if-else-red-15cm-copy-2

-> Robot did not move forward because the condition it's not met. So, it's false.

-> Because ONLY ultrasonic sensor "less than 15cm" BUT not Color sensor.

BOTH condition have to be fulfill in order to meet the condition.

So, robot move BACKWARD.

True:

true-and-ifElse
6-And-if-else-red-15cm

-> [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] is detected. Condition it's met.

-> Robot move FORWARD

"OR" operator

Or-operator

For example:

->Is it true that ice cream OR fried chicken: food?

Yes. So, this is true

-> Is ice cream OR fried chicken: machines?

No. So, this is false

Or-example

"OR" operator combines two conditions and returns true if at least one of the conditions is true. It's represented by the symbol "||".

For example:

Condition 1: Color sensor detects blue

Condition 2: Color sensor detects red

Combined Condition: Color sensor detects blue || Color sensor detects red.

Repeat Until "Or" operator

3-OR-red-15cm

1- Repeat [Robot move backward at the speed of 50%]

2- Until [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"]

3- Stop moving

True: Color Sensor "red"

or-true-red-until
3-OR-red-15cm

The robot either [Color Sensor detect "red" OR Ultrasinic distance "less than 15cm"]. Color sensor detected "red", so condition is met.

True: Ultrasonic "less than 15cm"

or-true-ultra-until
3-OR-red-15cm-copy-2

The robot either [Color Sensor detect "red" OR Ultrasinic distance "less than 15cm"]. Ultrasonic sensor detected "distance less than 15cm", so condition is met.

If-Else "Or" operator

5-OR-if-Else-red-15cm

IF

1- If [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] condition is met

2- Robot move FORWARD at the speed of 50%

ELSE

1- If [Color Sensor detect "red" AND Ultrasinic distance "less than 15cm"] condition NOT met

2- Robot move BACKWARD at the speed of 50%

True: color sensor "red"

or-red-ifElse
5-OR-if-Else-red-15cm

The robot either [Color Sensor detect "red" OR Ultrasinic distance "less than 15cm"]. Color sensor detected "red", so condition is met.

True: Ultrasonic "less than 15cm"

true-ultra-ifElse
5-OR-if-Else-red-15cm-copy-2

The robot either [Color Sensor detect "red" OR Ultrasinic distance "less than 15cm"]. Ultrasonic sensor detected "distance less than 15cm", so condition is met.

Time for a quiz!

Question goes here