Welcome back.
In this video, I want to show you a slightly different way of using if statements.
So I have this int month.
Now that I set to five then I have this string month name and then I have this if statement that has
a bunch of else ifs and an else.
So you see the difference between them is that here I'm using curly brackets to set my code up.
That will be executed once this statement is true.
Okay.
However, if I have a statement that is just one line of code, I don't need to use the curly brackets.
So if it's two lines of code then I need to actually use.
Then I need to actually use two lines of code.
So here for example, if I were to then say int or month equals two for example, then that is fine.
But here I couldn't do that.
So let's say I want to add another line here.
Month equals three.
Like so.
Then it will jump into the beginning of the line.
So suddenly this code is incorrect.
So this will not work because I don't have the curly brackets around it.
However, if I only have one line so this is just one line of code, then I can have it after the if
statement directly.
So here you see it's indented with a tab.
So this is a tab wide so to speak.
And by doing so this is valid code.
But once you need multiple lines of code then you need to use the curly brackets.
However by default I will just recommend to always use curly brackets.
Then you don't have that problem where you ever come into the situation where you're creating chaos
or code that then can run into problems later on.
So this here, however, does look nicer, right?
If we look at it, it just does look so much cleaner.
If you look at this code instead of having a bunch of curly brackets.
Now there are people who set the curly brackets at the top here.
So for example, like this, that is fine as well.
That works, but by default Visual Studio just puts it into a separate line.
So then you know exactly which code is part of the code that will be executed once this if statement
is true.
Okay.
And once we get to the line seven in our runtime okay.
So that's just a little something that I wanted to show you.
See you in the next video.