Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. The Logical Operators

The Logical Operators

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 1.6k Views
  • 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.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

     

    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
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode