Conditions

Well their names says everything about them. Let me start this with an example: You're telling someone to choose cloths and you say "If you want to wear a black t-shirt you obviously need a blue Jeans but if you're going to wear a tux you should wear it with it's own pants" conditions are just like that. If something happened or if someone did something then do something. Conditions in Arendelle are like this:


{ Condition , Code } 

If condition happens then the Arendelle runs the code but and else way nothing happens.


Example

Look at this code:
{ 1 = 1 , p } 

It's most obvious that 1 is equal to itself so when Arendelle sees that the equations is true it runs the `p` code:

Example


{ 1 < 2 , p }

Because the 1 is less than 2 Arendelle runs the code:

Example


{ 1 = 10 , p } 

Well 1 is to equals to 10 so Arendelle never runs the code.




## How to write a condition You may ask what are other other condition operators? There are few of them: | operators | What they does | |:--------------|:------------------------------| | `=` or `==` | Equals to | | `!=` | Not equals | | `>` | Greater than | | `<` |="" Less="" than="" `="">=` | Greater than or equals to | | `<=` 10000="" |="" Less="" than="" or="" equals="" You="" may="" ask="" why="" there="" is="" `="=`" available!?="" As="" my="" opinion="" it's="" one="" of="" the="" most="" funny="" things="" about="" programming.="" Have="" you="" seen="" *Spy="" Kids="" 2*="" movie?="" There="" a="" watch="" in="" movie="" that="" has="" more="" but="" it="" can="" tell="" time="" because="" developers="" were="" so="" buzzy="" creating="" all="" those="" functions="" and="" they="" forget="" to="" write="" clock="" for="" watch!="" same="" story="" In="" other="" languages="" programmers="" chose="" be="" operator="" defining="" variable="" (no="" rush="" we="" will="" learn="" what="" variable)="" when="" came="" build="" conditions="" just="" remembered="" have="" find="" new="" replacement="" was="" token!="" So="" created="" instead="" make="" possible!="" To="" take="" care="" who="" used="" are="" two="" ways="" `Equals="" to`="" Arendelle.=""

Example

`!=` means if the equation was `false` do something so look at the following code:
{ 1 != 2 , p }

Arendelle read your code and because 1 is not equals to 2 it runs the code.


Also there is something very fun about not using any operators for example:
{ 2458 , p }

I said condition, condition is about being `true` and `false`. If something is not `false` then it's surely `true` so do you think that 2458 is `false`. You may say: "It's a number! How can a number be false?" and you're right so what that is not `false` is `true`! When Arendelle reads your code it passes the number as `true` and it evaluates the code.

{ 1 = 1 , p }
{ 1 = 2 , p } 



And / Or operators

`And` and `Or` are what we use to handle multi conditions for example look at the code below:
{ 1 = 1 and 2 > 1 , p }


As you see there are two equations `1 = 1` and `2 > 1`, so when Arendelle reads them it evaluates them and finds out that they are both true. `And` operator says that both equations must be `true` and they are so Arendelle runs the code. Now look at the following code:
{ 1 = 2 and 1 = 1 , p } 

As you see because not both sides of the `and` are `true` Arendelle never runs the code, Meanwhile the `or` says at least one side of me must be true so for example :
{ 1 = 2 or 1 = 1 , p } 

Runs because one side of the or is `true` but the following code never runs because there is no `true` in each side of the `or`:
{ 1 = 2 or 1 = 1 , p } 



Else

The more complete rule of condition is:
{ Condition ,

   Code for when the condition is true
 
,

   Code for when the condition is false

}

So as you see the grammar has a one optional part, So if the condition's answer be `true` Arendelle will run the second part of the grammar like the previews one but here's the new thing. If the condition's answer be `false` Arendelle will run the last part.


Example

The fun thing about programming is to understand anything you can just try them! do you see this code:
{ 1 = 2 ,

    [ 10 , r ] 
   
} p

Because the condition is `true` you will see this image:


Now look at this code :
{ 1 = 1 ,

    [ 10 , r ]
, 
    [ 5 , d ] 
   
} p

Because the condition is `false` you will see this result:


But when you add `else` to your condition you can say *What to do if the condition is true* and also *What to do if the condition is false* like this:
{ 1 = 1 , rrr , ddd } p

Because the condition is not `true` Arendelle will run the code `ddd` and if the condition be `true` instead of `false` Arendelle will run `rrr` code. That is what else does




New sources

Well you know `#width` and `#height` but it's time we go a little further and learn two awesome new sources `#x` and `#y`, As we said before Arendelle is a grid system something like a chess. In the we have a row of numbers from 1 to 8 and row of characters from A to H we use them to specify an exact place in chess like when we say: *Move the knight from G1 to F3*.
Just like chess Arendelle uses this technique, Each dot in screen has an address comprised of two coordinates, The x-coordinate and y-coordinate. What are those? Look at this photo:

![](https://raw.githubusercontent.com/pmkary/pmkary.github.io/master/GitHubWideImages/Arendelle/book/Coordinates.png)

Now what are `#x` and `#y` sources? They tell where is the pointer in the screen. for example look at this code we did together in the basics chapter: ``` rp rdp dp lp lp ``` If you run the code this will be the result in the coordinated screen:

![](https://raw.githubusercontent.com/pmkary/pmkary.github.io/master/GitHubWideImages/Arendelle/book/coordinated-rprdpdplplp.png)

All codes begin from the origin ( `#x` = 0 and `#y` = 0 ) then in our code pointer moves right and then paints the `#x` = 1 and `#y` = 0, pointer then moves to right and then down and paints the `#x` = 2 and `#y` = 1 after that pointer goes down and paints the `#x` = 2 and `#y` = 2 so on till it finish on the lighter gray dot with address of `#x` = 0 and `#y` = 2:

![](https://raw.githubusercontent.com/pmkary/pmkary.github.io/master/GitHubWideImages/Arendelle/book/coordinated-withlastdothighlighted-rprdpdplplp.png)

Now we can always use `#x` and `#y` to understand where we are. You may ask how can we actually use it? When look at this example!


Example

Imagine we're going to paint the dots with these addresses: - Dot 1 : `#x` = 3 and `#y` = 0 - Dot 2 : `#x` = 6 and `#y` = 0 - Dot 3 : `#x` = `#width` - 5 and `#y` = 0 As you see they are all in one line because their all `#y` coordinate is zero so we can create a code like this:
[ 3 , r ] p
[ 3 , r ] p
[ #width - 11 , r ] p

And if you run the code you'll see it works fine:


But you can write your code a bit more fun this way:
[ #width ,

    { #x = 3 or #x = 6 or #x = #width - 5 , p } r
   
] 

As you see the code moves the pointer to all the dots in the line with `#y` = 0 and then if `#x` was address of one of those 3 dots Arendelle paints that dot, Now look at this code's result:


Results are same but the final code is much more readable to a human eye.




What can we do with all this stuff?

That's a good question. In other languages conditions are the most used grammars but in Arendelle loops are the most used ones, However conditions are still in the second place. We will use them so much, Since you know everything about conditions we will start experimenting our knowledge.


Example

As I said in the Hello World chapter you can show messages in Arendelle's title by writing them between two apostrophes like this:

'message'

Now have you seen those apps that says you're screen size is too small for the software to run? Let's build one of those! If the screen be more than 50 we will get yes and if the screen be less than 50 we will get an error saying you're screen is too small:
{ #width >= 50 , 'Yes!' 'ERROR: Screen width is too small'




Oh! You just wrote you're error message! wasn't it fun? I have coded too much for you today so let's continue by some field work!


Exercise

Write a code with conditions to paint half of the first line like this (and remember to use a condition to do it!)






Exercise

Create a script to check all the dots of the screen and then if their `#x` address was less than 11 and their `#y` address was less than 6 paint those dots like this:





Actually condition is so important and we are going to use them to do extra ordinary things do the last example because I'm going to show you something very very special in the next chapter!! We are going to create a Graphing Engine!!! You can show other people you created one in your first programming lessons!!!