 Welcome back, in the previous segment, we discussed the following things. We discussed the repeat statement and the C and C out statements and some commands to compute mathematical functions. Actually we also discussed the statement by which we can reserve locations or cells in memory. Now in this segment I am going to make some general remarks about C++ programs. First of all let me observe that a program is really a sequence of statements or commands and it has to be written in a particular manner. So the keyword main underscore program must appear first, followed by an open brace. After that the sequence of statements representing the main program have to be put in and finally the closing brace has to be put in. A statement or a command is typically terminated by a semicolon. So the semicolon is the C++ equivalent of the full stop of the English language. Just as in the English language a sentence ends with a full stop. In C++ a statement or a command ends with a semicolon. And just as you read sentences top to bottom left to right on a page written in the English language, similarly C++ programs are also executed by reading the statements top to bottom and left to right. Now some of the statements require additional data for them to do their work. So for example if I write forward I need to tell the computer how much I want to move forward. So such data is called an argument. The right needs to be told how much angle. So this is another argument. There can be commands which require more than one argument and we will see them soon. And there can be commands which do not require any argument at all. So turtle sim for example did not require any argument. And so in that case we just put that opening and closing parenthesis immediately. Even in the discussion about languages or especially programming languages the term syntax is used. Syntax, the term syntax is used to refer to the form or the grammar which the language is supposed to follow. So syntax refers to the grammatical rules indicating how commands must be written. And the syntax of programming languages is very strict. What do I mean by that? Write 90 cannot be written in any other form. For example you cannot write it as write space 90 that is not allowed. The parenthesis are necessary. However, you could put a space before and after the parenthesis that is allowed. However, you cannot split the word write. So you cannot write R space IGHD that is not allowed. You cannot even capitalise the R. So it is strict in a certain sense and you have to understand in what sense the language is strict and you have to adhere to it very, very precise. So pen up for example cannot be written as pen lowercase up. So the U is expected to be capitalised. Usually the parenthesis are needed so you cannot just leave out the parenthesis. There are other statements also which we will learn and they will also have their syntax and the programs will have to be written strictly in that syntax. You might say that look what is the big difference between pen lowercase up and pen uppercase up. Isn't it common sense? Well it may be common sense to you and me but a computer requires you to be exact. So a computer will think of pen capital up as something different from pen lowercase up. So if you want capital up you have to say capital up. However, in spite of all this there is a lot of flexibility allowed. So for example I already said that you can put spaces which do not split a word or split a number so you can put a space before or after the parenthesis. In addition there are some other natural features as well. So wherever we say that look put a number over here usually you will allow a numerical expression also. So for example in a repeat or in a write rather in the write we can put an expression such as 360 divided by n sides or it could be n if n is the name of a variable. So wherever a number is going to appear you can put in the name of a cell in memory or you can put in an expression which depends on some values. So that kind of flexibility is there. And also there is another flexibility which is that we talked about a repeat statement which has a body and we said that the body consists of several statements. One of those statements could be a repeat statement itself. We will come to the example of a repeat inside a repeat but let me make few additional remarks. So first of all I am going to tell you about something called comments. Now a program is going to be executed on the computer but it will also be read by people. So you might write a program and your teacher might read it. If you are working your boss or your colleagues might read the program you have written or you might write a program and it might be so good that you may give it to several other people all of whom might read that program. Now if you write a program it has to be understandable. So you might want to say something more in addition to the statements on it. So for this purpose you can place something called comments in your program. How do you place comments? Well you can put comments between a slash star sequence of characters and a star slash sequence of characters. So whatever appears between these two sequences will be thought of as a comment. Typically I can put slash slash and then I can put a comment after it and the comment ends when the line ends. So typically the first form is used to define a long comment which extends over several lines. The second form is used to define a short comment which is really put which really extends over a single line or which is really put at the end of a line. Now a comment is really meant only for the human readers and the computer completely ignores. The computer does not care what you put in a comment. So we had our program for drawing that polygon. So I have put two comments in this. So first at the top I have put a comment which tells who the author of that program is and it tells the purpose of that program. So this is usually good practice. So you should put your name on programs so that if somebody has questions they can come and talk to you and also you might as well tell them what is that program going to do. And then over here we did something like dividing 360 by n sides. A reader might look at this and say look why are they dividing 360 by n sides. Now if you want to help out those readers you can say that the exterior angle of an n sided polygon is 360 by n. I want to draw an n sided polygon and therefore I will turn by the angle 360 divided by n or in this case n sides. So that is how comments help. They do not help the computer but they help human readers and you are extremely, extremely emphatically encouraged to write comments. For one thing you will help your friends and boss and your teacher but you will realize that you write a program today in a week or so you will completely forget what you have written. Maybe you will look at this program and ask yourself oh why did I write 360 upon n sides. To help yourself at least put in a comment. You will be really, really grateful and this is a required good practice if you become a professional programmer. Another important practice and another part of how you write programs is so called indentation. So here is the same program and I am going to tell you what indentation is inside it. So notice that at the beginning of some lines some space is inserted. So for example before this turtle seems some space is there. In the body of the repeat there is a space which offsets it from the repeat statement itself. So this space is called indentation. The indentation allows you to quickly see which statements constitute the body of the repeat or which statements are part of the main program. So for example this includes simple CPP is not a part of the main program. Whereas all these statements are. So by offsetting I can visually quickly note that look this is the main program over here or I can visually quickly note that oh this is not only in the main program but it is also in a repeat statement inside the main program. So you may guess the general rule if some x is inside some y then typically you will put two additional spaces before every line of x. So that is what has happened over here for the body of the repeat which is sort of supposed to be inside the repeat statement and these are the statements inside the main program. So you have put two spaces over here. Then there is also a style that you have to master as to how you write the opening brace and the closing brace. So you can see that the closing brace goes back, reverts back to the old indentation. So again it is considered extremely unfriendly if you do not use indentation and again for your own benefit you should use indentation because when you come back to the program it will make it much easier for you to understand what you yourself have written. And of course indentation is useful for human readers but is ignored during execution. Now we said that the body of a repeat itself can contain a repeat statement. So here is an example. So we have a repeat 4 and inside that there is a repeat 3 and a write 90 statement. So how does this execute? Well the first rule is that whatever is inside this outer repeat is going to be executed 4 times. So what is inside this outer repeat? Well there is a repeat 3 and a write 90. So we are going to execute this statement 3 times, then we are going to execute this statement once, then we are going to go back again, execute thrice, execute once and so on. Do this 4 times. That is what the rule is. There is no real mystery as such. So let us try to figure out what this is doing. So let us just look at one iteration of this repeat. What is it doing? So it is going to go forward 10 steps. So let me draw that and to begin with let us assume that the pen is down. So here is the turtle, it goes forward 10 pixels. At this point the pen goes up. Once the pen goes up the turtle goes again forward 10 steps. But it goes forward and this time the pen is not down so there is no line drawn. But at this point the pen is put down again. So this finishes one iteration. What happens in the second iteration? Again a forward line is drawn, again a movement is there without any line being drawn. And one more iteration, a line is drawn and there is a movement again. So this finishes one iteration of that repeat 3 statement. After that we continue forward and now there is a write 90. So the write 90 will cause, so earlier the turtle was pointing in this direction. So write 90 will cause it to point in this direction. So that ends an iteration of the outer repeat. So again we start from the very beginning. So we go back to the top of the repeat 4 and we start executing. So now we are executing the second iteration. So for the second iteration again the repeat 3 is going to be executed. So this will again cause forward 10 and then pen up and forward but this time the pen is high so that nothing will be drawn. So that is just one iteration of the inner repeat. So one more iteration movement, one more iteration which consists of this movement and again we come to the bottom of the repeat 4 this time at the end of the second iteration. So at this point the turtle was pointing in the downward direction. It now turns right and points in this direction. So now one more iteration will cause again this movement forward. So drawing but forward without movement and drawing forward without movement. Movement and drawing forward without movement and again will turn right. So the turtle will start pointing in this direction. So again it will execute forward and draw, forward without draw, forward and draw, forward without draw, forward and draw, forward without draw. So the turtle will end up at the same place. After that it will again turn right so it will end up facing in this direction. So the turtle will start facing right over here. It will draw these dashed lines, draw these dashed lines, turn, draw these dashed lines, turn, draw these dashed lines and again turn and come back to the same position and have the same orientation. So notice that repeat within repeat is very, very useful. Imagine if I had wanted to draw a long line with lots of dashes. I just have to make that repeat 100 if I wanted 100 dashes. I do not have to write 100 statements. So again a quick summary of what I just said in that example. In general if I have a repeat x, y, y, y statement it means execute y, y, y, x times. Now if y, y, y itself contains repeat w, z, z, z then z, z, z is executed w times in each execution of y, y, y or in each execution or in each iteration of that outer repeat x, this repeat w, z, z, z is going to be executed. And in a single execution of repeat w, z, z, z, z, z is actually executed w times. Now I can have as many repeats going on inside each other or nested inside each other. So what is the logic there? Exactly similar. So as a quick exercise what do you think this program is going to do? So figure this out yourself and only then advance forward. So give yourself a few seconds. So I will not explain it but I will just show you the solution and so you can compare your answer with it. You can also type this program in and you can see exactly what it does. So the program will print this. So now I want to talk about some terms which you will hear commonly when you discuss programming. So you will hear people say that control is at statement w. This means that the computer is currently executing statement w or people talk about control flow. Control flow is how the control moves or the order in which statements get executed. So execution starts at the top and goes down and the execution is retraced if there is a repeat statement. So the control flows over and over the body of a repeat statement. The term variable is also used. A variable is simply the region of memory designated for storing some value that you need. So the insights that we define is actually going to be called a variable. So we said that we use a cell in memory but that cell is going to be called a variable because we have said we have asked for it and we said that we are going to store some specific kinds of values over there. Why is it called a variable? Well because we are allowed to change the value that we store over there. Exactly how this change happens we will see a little bit later. So here is what we discussed in this segment. We discussed the general notion of a program. We discussed the notions of syntax and terms which has control flow and then we made this observation that repeat statements can be nested inside other repeat statements. So we will take a quick break.