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:
- If thereβs some condition
- 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
Add a βͺοΈ
statement that accepts the condition π
. Then, add an empty code block using π
and π
.
Inside the code block, add a print statement using πβοΈ
and print out a string of your choice! For example: π€I'm π of the world!π€
.
Now just play around with the code:
- Try changing the
π
to aπ
. - Add in more
πβοΈ
statements. - Create additional conditionals.