Navigation

    CreatiCode Scratch Forum

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

    If < > Then ... Else ...

    2D Blocks
    1
    1
    317
    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
      • 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.


       

      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.
      If the condition is “false”, it plays the blocks which come inside the second C shape.


       

      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.
      If the condition is “false”, it takes the value of the second input.


       

      Nested If <> then, else Blocks

      If you put one “If then, else” block inside the other, they become “Nested”.
      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”.


       

      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.


       

      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.


       

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