Learn
Conditionals
The β†ͺ️ Statement

As we previously mentioned, we do things based on our present conditions. Like, if we’re hungry, we’d get something to eat; if it’s raining, we would carry an umbrella.

How our actions follow the same:

  1. If there’s some condition
  2. Take some action

Using Emojicode, we can add this decision making ability into our program using the β†ͺ️ statement. This β†ͺ️ checks a condition and if the condition evaluates to πŸ‘, it runs a block of code.

Take for instance:

β†ͺ️ πŸ‘ πŸ‡ πŸ˜€ πŸ”€The condition is πŸ‘πŸ”€β—οΈ πŸ‰ πŸ’­ Prints: The condition is πŸ‘

Notice how we added the πŸ‘ after the β†ͺ️. Then we follow up with a block of code using πŸ‡ and πŸ‰. Inside the block of code, we added πŸ˜€β—οΈ to print out the string πŸ”€The condition is πŸ‘πŸ”€.

If we change the condition from πŸ‘ to πŸ‘Ž like so:

β†ͺ️ πŸ‘Ž πŸ‡ πŸ˜€ πŸ”€The condition is πŸ‘πŸ”€β—οΈ πŸ‰ πŸ’­ Nothing prints

Our code block doesn’t run since our condition is πŸ‘Ž. Therefore, we wouldn’t get anything printed to the terminal.

Let’s create our own conditional to see it in action.

Instructions

1.

Add a β†ͺ️ statement that accepts the condition πŸ‘. Then, add an empty code block using πŸ‡ and πŸ‰.

2.

Inside the code block, add a print statement using πŸ˜€β—οΈ and print out a string of your choice! For example: πŸ”€I'm πŸ‘‘ of the world!πŸ”€.

3.

Now just play around with the code:

  • Try changing the πŸ‘ to a πŸ‘Ž.
  • Add in more πŸ˜€β—οΈ statements.
  • Create additional conditionals.
Folder Icon

Take this course for free

Already have an account?