Logic
The Logic section is your gateway to creating intelligent and adaptable robot behaviors. It houses a collection of blocks that enable decision-making, conditional execution, and control flow in your programs.
if do
Allows you to execute specific code blocks if a certain condition is true.
Key points:
Condition: This is the part of the block where you specify the condition to be evaluated. It can be a comparison, a boolean value, or the result of a sensor reading.
Do block: This block contains the code that will be executed if the condition is true.
if do else
A fundamental control flow structure that allows you to execute different code sections based on whether a condition is true or false.
Key points:
If condition: Specifies the condition to be evaluated.
Do block: Contains code to be executed if the condition is true.
Else block: Contains code to be executed if the condition is false.
if do else if do else
Control flow structure in FTC that allows you to execute different code sections based on multiple conditions.
Key points:
If condition: Specifies the first condition to be evaluated.
The first do block: Contains code to be executed if the first condition is true.
Else if condition: Specifies the second condition to be evaluated if the first condition is false.
The seconds do block: Contains code to be executed if the second condition is true.
Else block: Contains code to be executed if none of the previous conditions are true.
comparison operators
Returns true if both inputs are equal to each other.
Key points:
The two inputs must be of the same type.
There are more comparison operators that you can choose from the drop down list shown below.
and
Returns true if both inputs are true.
Key points:
Used to combine two conditions.
Returns true only if both conditions are true.
Returns false if any of the conditions are false.
or
Returns true if one of the inputs is true.
Key points:
Combines two conditions.
Returns true if at least one condition is true.
Returns false only if all conditions are false.
Can’t find it? You need to first choose ‘and” box, then choose “or” from the drop down list.
not
A logical operator used to negate a condition.
Key points:
Reverses the logical value of a condition.
Returns true if the condition is false.
Returns false if the condition is true.
true/false
Often referred to as Boolean values. Default is true. You can choose false from the dropdown list.
True: Represents a logical condition that is satisfied or correct.
False: Represents a logical condition that is not satisfied or incorrect.
Key points:
Conditional statements: Determine the flow of a program based on whether a condition is true or false.
Logical operations: Combined with operators like AND, OR, and NOT to create complex conditions.
Boolean data types: You could define a variable to store and manipulate true/false values.
null
Represents an empty or non-existent value. It's often used to indicate the absence of data or an undefined state.
Key points:
Represents absence: Indicates that a variable or object has no value assigned.
Error handling: Can be used to handle situations where a value might be missing or invalid.
Placeholder: Often used as a default value before data is available.
test if true if false
Check the condition in “test”. If the condition is true, return “if true” value. Otherwise, returns the “if false” value.
Key points:
“if true" and "if false" values can be of any time.