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. If < > Then ... Else ...

If < > Then ... Else ...

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 1.5k 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
    • The “If <> then” Block

     

    Description

    There are two “If <> then … else …” blocks in the control category. One is a C block and the other is a Reporter block.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/5cc665f2-baa9-4cf2-82cf-be7c38e0048d.PNG" width="650" style="">
     

    How do these blocks work?

    The C Block

    The C block checks if the condition is true or false.
    If the condition is “true”, it plays the blocks which come inside the first C shape. https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/fc38de87-c35c-43d6-9680-b1eac31edfab.PNG" width="100" style="">
    If the condition is “false”, it plays the blocks which come inside the second C shape. https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/227acf4d-254f-4aae-a6ac-49c27ad4e93b.PNG" width="100" style="">

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7250c2e8-432b-4019-9942-2aaf8c7ae86a.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
     

    The Reporter Block

    The reporter block also checks if the condition is true or false.
    If the condition is “true”, it takes the value of the first input. https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ca1751e0-76f1-4a16-bbd4-1e9fa3fdc1a5.PNG" width="400" style="">
    If the condition is “false”, it takes the value of the second input. https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/45dcd2d6-8c8b-4a89-88ad-96e54a4af709.PNG" width="400" style="">

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b6dbdb04-45ba-4cba-82a8-35d20791c30d.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
     

    Nested If <> then, else Blocks

    If you put one “If then, else” block inside the other, they become “Nested”. https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f35a9617-89cd-4886-90ba-0b95bdb14dea.PNG" width="150" style="">
    You can use nested if <> then, else blocks to check additional conditions based on whether the first condition is true or false.

    For example, as shown below, the first “if” block checks if the score is greater than or equal to 20. If it’s true, then the backdrop changes to Level 2. If it is not, then the second “if” block checks if the score is greater than or equal to 10. if it’s true, the sprite says “Good job! keep going!”, or else it says “Hurry up”.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/95099ecd-3cab-47ab-9c7b-4eab72eb96e9.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
     

    Multiple If <> then, else Blocks

    You can stack multiple “If then, else” blocks together to check multiple conditions one by one.

    For Example, as shown below, If the sprite touches the Red ball, it says “I found the red ball” or else it moves to a random position. And then if the sprite touches the Yellow ball, it says “I found the yellow ball” or else it moves 10 steps.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f556a171-3034-4749-b1a9-4cd8450a1872.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
     

    Checking the condition repeatedly

    The “If then, else” block checks its boolean condition only once. You can use a Repeat or Forever Loop if you want to repeatedly check the conditions in a game or project.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/add6aef7-38ca-4b4b-b3ad-f48c5874887f.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
     

    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