# 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.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcao5h4qAM8tXp3Vltum0D-aoFA4YmaskUt7S3OIu5aCpnlohhfODl4wU3yfQnDDhIT0Q9dsQH2uNlmXW9qvc2UwCbs2-RSQLeJC_I1ckkBJkto0FCFbppPM67yVfR6MFIsY6WuZoxOkls9VjUpMCK3UsA?key=hRw9bBhBfp1lHBJ7rUAI2Q)

**if do**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdxGHg_gPQKL_hOwPmLMgqrGU8BMOGJNxk01v2WlQR826i1C-pt0xhCqSuhs_GSwpaRDZocBtuzHYzImg2Cu2_HM4BNA0fSoQTT7cLbmQMwZ_QCryd3KEHKI7Q5jXOhgpi1rHQnVFqvy2BjLumLh7eXpPcE?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcu53d5LZXtndtj931MOlOotuX5ge2_O4b95zee-1BMGFmyeSx3XYcV-njozkHwk9GHxwSAMfkNJiMBL2S6Vik5La5alRNsgpxIs5CtZgi647S7-P3nzUhwFQF42xnPqVBZnnA7a3CmsIcFwu5-aKHDbSnF?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfkhuFNuwJrc8wKgQwmHPC9PHdOtZ_fEbbL4jjXYOnFdUUVObwnETR_82uaBNobFlsmIXgtCFif3EeGtl45Drplrd7T9gW_QV8ZUj7waXCjodZzl3wzvziwEqYrT93tTChr4Dq8XnyaOOQp_Wnc-85F-XY?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfyWhNadi5BEagj32UoRVfQ2rDf7nO2aerzaVTUTyTpGESg_p70LvxefF-ejuw4CMr-8fvCpx9xR7gihD7qW924gztLoTDv2CTDYSXrwQ1kBgT-nBODsS_N7YghDD9Xpz78hbghhgyWoKDpGkS5zL-Q2ml9?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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.

\\

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdaON_h06ppT-ew7ISY04HpmRb-Iymzg18qUzz0ph-opd9xnHYSap_4QDZ6wzvG6COFdsQ3R0g1fPeGTmirwIrX_Vjo9fvkMMj-m85EWgbmDvHPYCpPeDHC_kkAJ_fTLqZt-GSODotMhha1UINytgn5d3Vu?key=hRw9bBhBfp1lHBJ7rUAI2Q)

**and**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfqAJeGF2StXVrH8p2Ye4axVpDwCoYP1qTTRpEXpHzG2O4_9C_ql7-sG89gAJps8xPrjNcZ5s_eKF2Jk4q0cM7ToJD51LW0kYjSAiuhnKE78fYy_UbzatUVWYAeM1eI0CTNkSACnY_894gK6m1x8OrncJg?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Returns true if both inputs are true.&#x20;

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**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXez_6f2RQt4o3rkH5xiSJsWz6n6YmNjc2PimTFjWR7J82ykGz2c--HIqLBCR1kUDXxxqzHoS418roYNQUZgUatNl74FgU0yvq-EW0OjywC4QVqImFIzcpx3AL0HAX1occSZJNB6NazYkSXbNIYh1WXVgaMz?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeaJePfSymW8QdR51TqNCeCkWDrpbOhyRI7zg05CPV4z6UqzFTV1ucSsOF6mNVpJJToBltFLZedFE47o7dDw_XjoadP66gulGRv3-hq_jKeObjI4PjK11rQply9hpxtL8oBtXIWo8jee1EQP0_xf9XtmJX7?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXe5CEuBbabw2ntJAan5hK-ANJZWepRsWXSQkqnspXlapHxpyc3I4E0bpeOmd7PfIOYBT8laIKmFlTZufhUIGD9jcgNwFIR-F3tp_fBUt-X6mjm-nN92zTKiFFO5gso0WiGZGvpAqo5NON_P_25PMDXFyTGS?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXe-KGrJE49LQFd63W2WYi3I58X2HHJnMokNFcsOaPJ7R9zSIwB8djdgcaUo10KVr_ssv7T8p2duZagvmQLQ7l50xj5W_hXeM-EwVlYbLsEAAGl7uJmQKQ78WBOF6YIMDmR5rqCrEWXF9yELUnYGA5snD91s?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfHSyp2SJ7gIU8UaKjc_V5G4rozcCJ7pJNIAiNq1gO_4A349ng-n77aG8YaUmT94tlp6ta_d19INFxKvgpkRUGHxqSrzSIsddt_E8KwX1kirJSXiTv1CG06Tnai7FABnzkZaXAOX6HghTNLHXsH6F1YKKM?key=hRw9bBhBfp1lHBJ7rUAI2Q)

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.
