Inevitably, whoever you are writing code for will dictate how you format code.
So sometimes it makes sense.
For example, if you use some form of pre-processing to extract code and definitions to create a documentations
for the code.
In many cases, this style that is imposed on you is the personal preference of someone else or you.
So there are two broad formatting styles in C plus plus and R and all men.
So in general K and R places the opening brace of a code block on the same line of the list.
Last statement, as you can see here.
Same line of line statement and same line of first statement, as you can see here.
But.
Uh, here.
As you can see, this is the typical typically used in Unix operating systems, but there is an Allman
still.
Allman still style is typically used in Windows, Microsoft Systems.
So the Allman style named after the developer Eric Allman, so places the opening brace on a new line.
As you can see here, this is the new line.
So the nested examples look nested example looks as follows here.
This is the.
An Allman style.
Um, and actually we will miss the else statement here.
Else and the test is false.
And here the second test.
Second test is false.
And this is the Allman Allman style.
So remember, remember that your code is unlikely to be presented on a paper.
So the fact that an R is more compact will save no trees.
If you have the choice, you should choose the style that is the most readable.
The decision of so for it's my decision is the is that R is more readable I think.
But if you choose Allman, it's completely okay.
So you can choose however you want.
Just don't mix.
Just don't mix those two code styles because it the code will become the unreadable here.
For example, if you mix the R and Allman, it's not okay, but it's syntax and compiler will compile
it with no problem.
So if you have a multiple nested blocks, the intense can give you an idea of which block the code resides
in.
However, comments can help to here.
So in particular, if a code block has a large amount of code, it's often helpful to comment the reason
for the code block.
So for example, if an if statement is the it is helpful to put the result of the test in the code block
so you know what the variable values are in that.
BLOCK So it's also useful to put a comment on the closing brace of a test here.
So.
Uh, let's, let's write an example program here.
Example.
Just an.
Example.
Example one.
Here.
So let's create an if blocks here.
If X, let's create first.
Let's create an integer.
Integer X equals one.
If X is is greater than zero, you will learn about all of this if and else statements in next lectures.
This is just an example.
So just keep in mind and here then x greater than this.
And here we will add the lots of code codes here.
And then lastly, if.
If.
X less than zero.
And let's add add an else statement to.
Else.
Else here.
Um.
Then as X.
Is greater than or equal to zero if.
So if x not less than zero, then x is greater than or less than zero.
So we just wrote it as comment.
So it just a comment.
So it's for easy to understand in next cplusplus programmers.
So here lots of quotes again.
Again lots of quotes and then.
If.
Here X is less than zero.
Just mentioning that this else is the if statement else.
So there's nothing else here.
If you put the this is a comment on a closing brace, it means that you have a search term that you
can use to find a test that resulted in the code block So the preceding lines make this comment redundant.
But when you have the code blocks with the many tens of lines of code and with many levels of nesting,
commenting like this can be very helpful.
So for example, oh, I'm searching for my x less than zero statement.
Where is the statement?
You just press the control plus f here.
Oops.
So ctrl plus f here and then x less than zero.
As you can see here, our idea of or you can use just a text processing application as well.
If you just use this commenting type, you will get the.
Uh, you desired search result.
In next lecture, we're going to learn about the writing statements.
So I'm waiting you in next lecture.