Hello and welcome.
In this video be introducing you to conditionals conditionals are called structures which allow you
to test if an expression or a condition returns true or not.
They are used to perform different actions based on different conditions.
The common condition conditional statements are an if statement basically an if statement is used to
specify a block of code that will be executed if specified condition is true.
We also have an else statement basically that checks the condition that is set within the if statement
is true or false that is false.
Then the code inside the else block will execute.
So the.
Else dead men will only come into effect if the conditions set within the if statement returns force.
So in my console I have called a variable here that I have defined call my number and I've given a value
of seven and a muse in an IF statement which is a conditional statement to test a condition so check
in if the variable called my name is equal to 7.
If it is the code this code here will be executed.
Which is answered a lot.
This means it will print out this message inside this console.
It will say look 7.
If the condition is true but the condition is condition is definitely true because a variable has a
value of 7.
I'm just checking here.
This is the condition.
The expression inside that if.
Which is this.
Here is the test.
Okay so this uses the identity operator which is post to here to compare the value to compare this value.
Here is 7 it is equal to 7.
If it is it will print out that.
So I'm just going to press enter and it all print out is 7 in the cons..
So in this case the condition is true.
So no other code needs to be executed.
However you can also create a condition in which you add an else statement so that the condition inside
the IF statement is wrong then a different block of code will execute which is located inside the elfs
block.
So here I've got another variable same chord.
My numbers have changed the value to 10.
And here I have included two statements.
The if statement and the L statement.
So what happens is the comparison is made.
The condition is tested and the test is a side.
If blockin said here so is testin If this variable.
My number is equal to 7.
This will return force because the value is 10.
So what happened this block of code here.
That said lock is 7 will not run so it will not get executed because the value is wrong.
So what happens.
It will skip the block and it will execute this code because this condition in siby if this wrong he
doesn't value it to 10.
So once a comparison has been made it all run code that matches the comparison.
So in this case the code inside the comparison is made inside the block.
So is testing the condition to condition as test to force because the value segment is not the 7.
So is now close to 10 so the block of code here says because 7 will not run.
Instead it will run this inside the console in the way you see cancelled on log.
Means is going to print a message inside the console so 5 press enter it can see your not very lucky
today because this condition that were tested did not evaluate to true.
So this quote here is executed debt.
So in a very simple example here to a lost trade how conditional statement works so there are other
types of conditional statement but the very basic is if the else statement.
So the key thing to note here is in the if else statement this The condition to be tested or the expression
to be tested is always located in the block.
So that's where you set the condition.
You can see how have set the condition here.
So if that condition does not evaluate to be true then the block of code inside the IF statement is
skipped the one in the else block is executed.
So in between the curly braces the opening calibrators And that's the closing calibrators is where you're
right the block of code that will execute.
You can see here this is the block for the here and in the elthorne you've got the opening curly braces
and the closing calibrators and in between you you've got the code block that executes.
If a condition within the if statement or if block is wrong.
So that's it.
I hope it makes sense.
If not please let me know.
Thank you and bye for now.