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. Operators for Comparing Values

Operators for Comparing Values

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 2.8k 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

     

    Introduction

    In the “Operators” group, there are 6 boolean blocks (>, <, ≠, =, ≥, ≤) for comparing between numbers or text strings. For example, you can compare between 3 and 5, or between “apple” and “orange”. The comparison result will be true or false.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/242130bd-99fa-4745-bcdf-244e0f2d3bb1.PNG" width="600" style="">

     
     

    Comparing Numbers

    You can use the 6 comparison blocks to compare 2 numbers, the same way how you compare numbers in Math.

    For example, when you run the block “10 > 5”, it will return “true”. However, if you ask if “5 > 5” or “5 > 10”, you will get a result of “false”.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/2d556c00-f6e4-4249-a6ff-ae8b8440137f.gif" width="500" style="">

    For a reminder, the ≥ or ≤ blocks will return “true” when the 2 numbers are the same. For example:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0b361660-ec8c-423b-8c9e-e78ca2517186.gif" width="500" style="">

     
     

    Comparing Single Letters

    If you are comparing single letters, such as “a” vs “b”, the computer will compare their positions in the list of a to z. For example, “a” is at position 1 in the list, and “b” is at position 2. Since 1 is less than 2, we say “a is less than b”. Obviously, the letter "z’ will be greater than any other letter. Here are some more examples:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/70fb6bbc-6440-42e4-bdc9-05d07e5b0910.gif" width="500" style="">

     
    Note that it does not matter if a letter is in upper or lower case. All letters are converted to lowercase before being compared. For example:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/06fdadf9-0cab-493b-a7ea-1eb4db85bb6c.gif" width="600" style="">

     

    Comparing Text of One or More Letters

    When there is more than one letter, we need to compare the 2 sequences of letters by each letter from left to right.

    For example, if we are comparing “cake” vs “cap”:

    • Position 1: “c” vs “c”, we get a tie, so we move on to position 2.
    • Position 2: “a” vs “a”, we get another tie, so we move on to position 3.
    • Position 3: “k” vs “p”. Since k comes earlier in the a to z list, we know “k” is smaller than “p”. Therefore, we can stop here and declare “cake” is less than “cap”.

    Here are some more examples:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/771c94ad-e912-452d-833a-106c21da0df2.gif" width="700" style="">

    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