Welcome to the second step.
In this step, you're going to learn about each statement and the condition expressions, and in the
end, I'll show you a few example projects using the if statement.
Let's get started.
Let's take a look at an example.
If statements, let's say that you have a program that prints messages depending on a basketball game,
play racecar, for example, if the score is higher than three, then it will say, good, let's create
the if portion of that program.
Now, I'm going to show you the whole program afterwards.
But for now, let's focus on the incident.
OK, now I'm going to type if.
Then I'm going to wrap the conditioned part in the parentheses like this.
Then I'm going to type scar greater than three using a combination operator.
If statement has its own block, its own scope, by the way, so I'm going to create a new blog now.
Then inside the blog, I'm going to type the good message.
If the score is higher than three, then it will bring good to the council, so far, so good.
However, something is missing, isn't it?
Yes.
Engo You can type an if statement like this, but you don't have to.
Let me show you what I mean.
But right, I removed the parentheses, unlike C based languages Engo, you don't have to type dependencies
unless you really need to.
This version is more concise, isn't it?
This statement is exactly the same as the previous one.
Now, let's take a look at the parts of this statement.
This part is the if statements blog, you know, what's a block, so I won't explain to you again,
just remember that a block creates its own scope.
So any declared names inside this F block won't be accessible by the outer blocks.
But if block itself and the following branches.
You'll learn what I mean by the branches soon.
No worries.
All right, let's continue.
This is a condition expression of the if statement, this expression should always yield a bool value.
You already know what a bull expression is, right?
So you can use any bull expression or a bull value here.
His, you know, goal type system is unlike other sea based languages, so you can't use in other value
than Abu in JavaScript, for example, you can put any value in a condition expression and it will work,
but not in.
Check out the example that I've created for you to show you this.
It's in the resources.
OK, these were the parts of this statement that are simple right now, let's talk a little bit more
about this condition expression.
They say that your program also evaluates whether a score is a valid one or not to do that here.
I'm going to use another expression with a logical and operator like this.
As you can see, the condition expression still yields value, right?
To combine these two expressions together, I've used a logical and operator that you've seen before.
Now, it only execute the if statements block if the score is higher than three and only if it's also
a valid score.
OK, by the way, sometimes I see code like this, which is written by beginners here.
It's clear that that valid variables type is a ball.
Right.
Or I couldn't have compared it with a true value here.
If so, then you don't need to type it like this.
Let's check it out.
This is better, isn't it?
As you can see, I'm directly using the valid variable here so you can use bool values directly.
You don't have to compare the.
By the way, let's say that you want to print the message only for the invalid's course, how can you
do that?
Let's check it out.
Here are used the not operator.
So now if statements blog will only run when the score is higher than three and only one if it's not
a valid score.
OK, now let's put this in a program context to understand better.
OK, good.
Now let's short declare score and valid variables like this.
Let's say that the player's score is five and it's a valid score.
So let's initialize the variables with those values.
Now.
OK, let's run its.
It brings good message into the console is because, as I said, the score is higher than three and
it is worth it.
Now let's change those variables.
They say that the player score is three this time.
OK, now let's try it again.
As you can see this time, it doesn't print anything since the score was less than three, so if statements
condition hasn't been executed.
OK, now let's say that you want to print another message and the score is equal and less than three.
To do that, you need to use an asset class in the next lecture, I'm going to show you how to do that.
So see you there.