Emojicode😎 (Conditionals)
Tags: programming, beginners, tutorial
Published: 2022-03-11 10:28:38

_Wuhuuu.. here comes the last part of the Emojicode series._

In this part, I'll introduce you to conditionals and how to make more complex programs with Emojicode 💪.

#### Conditionals 🙄❓
You are feeling hungry, what should you do? Well, eat! This is a conditional.
The condition here is - _If in this world I ever feel hungry then I should get up and eat 😋 else I should continue doing stuff that I actually procrastinate 😪._

In Emojicode, Conditionals take an expression, which is code that evaluates to determine a value, and checks if it is 👍 (true) or 👎 (false).

Using Emojicode, we can add this decision making ability into our program using the ↪️ statement. ↪️ checks if the condition is 👍 or 👎 and if the condition evaluates to 👍, it runs a block of code.

```
↪️ 👍 🍇
  😀 🔤Hello World!🔤❗️
🍉
 
💭 Result: Hello World
```

```
↪️ 👎 🍇
  😀 🔤Hello World!🔤❗️
🍉
 
💭 Result: *Nothing is printed*

```

Now, what happens when your condition is not 👍. _Like you have gone to your kitchen and you have nothing to eat. Oof, now you'll have to prepare yourself to go out and bring something to eat (hard work 💪)._
Here comes 🙅, this executes code for the backup plan.

```
👎 ➡️ foodPresentInKitchen
 
↪️ foodPresentInKitchen 🍇
  😀 🔤Take food, eat and live.🔤❗️
🍉
🙅 🍇
  😀 🔤Go out and bring something to eat.🔤❗️
🍉
```

#### Comparison Operators:

What about other data types, like 🔤(strings) and 💯(numbers).
We use comparison operators.
One of them is 🙌.

| Expression | Evaluates to |
| ------------- |:-------------:|
| 6 🙌 6 | 👍 |
| 🔤Hello🔤 🙌 🔤Hello🔤 | 👍 |
| 2 🙌 3 | 👎 |
| 🔤Emoji🔤 🙌 🔤code🔤 | 👎 |

_Now, you are in the market and you go to a shop. You need a pizza and a coke bottle. You are so extreme lazy that you don't want to go to two different shops to buy them. You look for a shop selling both. This is how you'll work:_

```
🔤Yes🔤 ➡️ shopHasCoke
🔤Yes🔤 ➡️ shopHasPizza

↪️ shopHasCoke 🙌 shopHasPizza 🍇
  😀 🔤No more hard work, get into the shop right away!🔤❗️
🍉
🙅 🍇
  😀 🔤Sadly, look for another shop 😭🔤❗️
🍉

💭 Prints "No more hard work, get into the shop right away!" because both have equal values that is "Yes"

```

**Other comparison operators:**

|Operator|	Operation|
| ------------- |:-------------:|
|◀️|	Less than|
|▶️|	Greater than|
|◀️🙌|	Less than or equal to|
|▶️🙌|	Greater than or equal to|

_Now, for the sake of continuing this senseless story, you are unable to find any such shop 😭. You can only get greens now._ 
Oof, you will need to chain one more conditional here that will execute if the above conditions are false but the new condition is true.

```
🔤No🔤 ➡️ shopHasCoke
🔤No🔤 ➡️ shopHasPizza
👍 ➡️ shopHasGreens
 
↪️ shopHasCoke 🙌 shopHasPizza 🍇
  😀 🔤No more hard work, get into the shop right away and eat happily.🔤❗️
🍉
🙅↪️ shopHasGreens 🍇
  😀 🔤Get right into the shop and eat sadly.🔤❗️
🍉
🙅 🍇
  😀 🔤Fellow human, sleep hungry today 😴🔤❗️
🍉
 
💭 Prints: Get right into the shop and eat sadly.

```

#### AND and OR (Logical Operators):
Sometimes we need to run a piece of code if all conditions provided are true but sometimes we need to run a piece of code even if one of the provided conditions is true.

_You are lucky enough to manage to get greens. You are in your kitchen trying to create a salad. You need salt, greens(of-course) and a plate to serve in._

![salad](https://c.tenor.com/K1BO0Kg3HbQAAAAM/salad-cat.gif)

```
👍 ➡️ hasGreens 
👍 ➡️ hasSalt
👍 ➡️ hasPlate

↪️ hasGreens 🤝 hasSalt 🤝 hasPlate 🍇
  😀 🔤Let's make a sal.. sal.. salad!🔤❗️
🍉
🙅 🍇
  😀 🔤First, get all the stuff in front of you.🔤❗️
🍉
 
💭 Prints: Let's make a sal.. sal.. salad!

```

_So you have two plates. One is white and other is purple. You are unable to find one but anyway anyone will work._ This is where we will use 👐 operator. This will execute the code once any of the condition evaluated to 👍.

```
👍 ➡️ hasWhite 
👎 ➡️ hasPurple
↪️ hasWhite 👐 hasPurple 🍇
  😀 🔤Let's serve our salad.🔤❗️
🍉
🙅 🍇
  😀 🔤At-least go and find either plate.🔤❗️
🍉
 
💭 Prints: Let's serve our salad.

```

### Other stuff that is not covered in this series.
a. You can group expressions like this:

```
🤜 3 ✖️ 2 🤛 ➕ 🤜 2 ✖️ 2 🤛
```
This is similar to: (3*2) + (2*2)

b. There are loops

```
🏁 🍇
   💭 Creating a list of text
   🍿🔤hello🔤 🔤hi🔤 🔤howdy🔤 🔤hiii🔤🍆 ➡️ list

   💭 Looping through the list
   🔂 typeOfHello list 🍇
     😀 typeOfHello❗️
   🍉
🍉

💭 Prints:
💭🔜
hello
hi
howdy
hiii
🔚💭

```
etc..

Every syntax of Emojicode can be found in the official docs. To become an emojicode master, go to their [official docs](https://www.emojicode.org/docs/) and play with emojis 💪.

### Yay, we have completed the Emojicode series.
See you again!

![cya](https://c.tenor.com/dndGxR4-vE4AAAAM/see-ralph.gif)