Emojicode๐Ÿ˜Ž (Conditionals)

knaagar

LeafKn

Posted on March 11, 2022

Emojicode๐Ÿ˜Ž (Conditionals)

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
Enter fullscreen mode Exit fullscreen mode
โ†ช๏ธ ๐Ÿ‘Ž ๐Ÿ‡
  ๐Ÿ˜€ ๐Ÿ”คHello World!๐Ÿ”คโ—๏ธ
๐Ÿ‰

๐Ÿ’ญ Result: *Nothing is printed*

Enter fullscreen mode Exit fullscreen mode

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.๐Ÿ”คโ—๏ธ
๐Ÿ‰
Enter fullscreen mode Exit fullscreen mode

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"

Enter fullscreen mode Exit fullscreen mode

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.

Enter fullscreen mode Exit fullscreen mode

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

๐Ÿ‘ โžก๏ธ 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!

Enter fullscreen mode Exit fullscreen mode

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.

Enter fullscreen mode Exit fullscreen mode

Other stuff that is not covered in this series.

a. You can group expressions like this:

๐Ÿคœ 3 โœ–๏ธ 2 ๐Ÿค› โž• ๐Ÿคœ 2 โœ–๏ธ 2 ๐Ÿค›
Enter fullscreen mode Exit fullscreen mode

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
๐Ÿ”š๐Ÿ’ญ

Enter fullscreen mode Exit fullscreen mode

etc..

Every syntax of Emojicode can be found in the official docs. To become an emojicode master, go to their official docs and play with emojis ๐Ÿ’ช.

Yay, we have completed the Emojicode series.

See you again!

cya

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
knaagar
LeafKn

Posted on March 11, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

#107 โ€” Sorting of Simple Members
programming #107 โ€” Sorting of Simple Members

November 29, 2024

While Loops
javascript While Loops

November 26, 2024

Exploratory Testing: A Detailed Guide
javascript Exploratory Testing: A Detailed Guide

November 25, 2024

Bookmarker
webdev Bookmarker

November 24, 2024

ยฉ TheLazy.dev

About