Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    The Logical Operators

    2D Blocks
    1
    1
    202
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

       

      Prerequisite

      • Working with Blocks

       

      Description

      The logical operators (AND, OR, and NOT) are Boolean blocks in the operators category. They take 2 boolean blocks as inputs, and produce an answer as true or false.


       

      The “AND” Block

      The AND block checks if 2 conditions are both true. It gives the answer “true” when both input blocks are true; otherwise, it gives an answer of “false”. There can be 4 possible input combinations:

      • true AND true ➡️ true
      • true AND false ➡️ false
      • false AND true ➡️ false
      • false AND false ➡️ false

      Here is how you can use the AND block with variables:


       

      The “OR” Block

      The OR block check if at least one of the 2 conditions is true. It gives the answer “true” when either input block is true; if both input blocks are false, the OR block gives an answer of “false”. There can be 4 possible input combinations:

      • true OR true ➡️ true
      • true OR false ➡️ true
      • false OR true ➡️ true
      • false OR false ➡️ false

      Here is how you can use the OR block with variables:


       

      The “NOT” Block

      The NOT block gives us the opposite answer to the input block. If the input block is “true”, then the NOT block would give an answer of “false”. If the input is “false”, then the NOT block would give an answer of “true”.

      Here are some examples:


       

      Combining multiple logical blocks

      You can insert logical operator blocks inside each other to check for more conditions at the same time.

      Here are some examples:


       

      Common Mistakes When Used with Variables

      Here are some common mistakes when using logical operator blocks with variables.

      1. X>10 AND X<10

      The variable “X” cannot be greater than “10” and less than “10” at the same time. So this condition will always be false, no matter what’s the value of the variable “X”.


       

      2. X>20 OR X=20

      The condition “X>20 OR X=20” can be simplified by using the **“>=” block.


       

      3. X>10 And X>20

      The condition “X>10 AND X>20” can be simplified to “X > 20”, because for it to be true, “X” has to be greater than 20, so the first part of “X>10” is not necessary.


       

      1 Reply Last reply Reply Quote 0
      • First post
        Last post