 Hello everyone, this is Siddish Kumar Ruttke working as assistant professor in mechanical engineering department, Vajran Institute of Technology, Shalapur. So today we will be discussing about loop control structures. When is the loop control structure used? Basically when we are repeating some process until a condition is satisfied. So we will be discussing about this, learning outcomes. At the end of this session, students will be able to develop different programs using various loop control structures. The following topics will be discussed in this particular video lecture. That is, first one is loop control structures. What is the loop control structure? What is the while loop? And what is the syntax for it? And what is the flow chart for? How will you write the flow chart for that particular while loop? Loop control structures. These are the statements which enables us to repeat some portion of the program either a specified number of times or until a particular condition is being satisfied. There are three methods by way of which we can repeat a part of program. They are using a for loop, a while loop, a do while loop. So we'll be discussing about the while loop in this particular video lecture. The while loop is basically used when you want to calculate the gross salaries of 10 different persons or you want to convert temperatures from centigrade to Fahrenheit for 15 different cities. Flow chart for the while loop. First basically it starts with a start phase or the start point which is called from where the execution of the program starts actually. Next is the initialization phase. That is initialization phase in this will give the minimum value. That is initial value for starting. If suppose I'm calculating the arithmetic progression from one to N numbers. Okay. The initial value will be one and the sum value will be for one to 100. This should go on repeating for one plus two, zero plus one one. So some value will be zero for this initialization step. Then is the test condition phase. In this test condition phase, we are checking the condition. That is from one to 100, we have given it whether one is less than 100 and two is less than 100. This will go on repeating up to 100 is less than 100. So when the when the condition is satisfied, that particular body of loop will be executed. And if it is false, suppose it is in the 101, it's greater than 100. It's not less than 100. So it will go into the false phase and whatever the output will be, the calculator will be displayed on the screen. So this is the body of loop. And next comes the increment operator. Increment is nothing but you're incrementing the value by one digit. And the false phase is stop phase. This is how the flow chart is written for the while loop initialized phase. We are giving the initial values called sum equal to zero, where some is an identifier or variable which is initialized to zero in order to calculate some of the series. For example, one to 10, I want to calculate the sum of the series. Test condition, that is one to 10, it is checked. One is less than or equal to 10. Using the relational operators, we are checking whether it is satisfying the condition or it may be the modulus operators. Increment value, value is incremented by the one while loop. The general form of while loop can be written as initialized loop counter, that is I equal to one, that is the starting initialized value. And sum equal to zero, if it is sum of the series. Then the while, that is test loop counter using a condition. Test loop counter using a condition, it may be using the relational operator. I is less than or equal to 10, or I is less than or equal to 100, or it may be I less than 100, so a different condition. When the condition is satisfied, then it goes into the body of the loop. Do this and this statement is executed. Whatever the calculation, it will be executed after the condition is satisfied. Then the increment loop counter. So next, with this while loop, we'll have just a question like, is the while loop an entry control or exit control loop control structure? When? In this particular while loop, actually we are checking the condition at the entry. So it is an entry control loop control structure. Now, let us take an example for calculating some of the odd numbers of the series. That is one plus three plus five up to 11. So basically it starts with a, that is in the C plus plus, it starts with the header files, that is io stream dot h header file, which h stands for the header file and io stream, that is, it mentions input output stream and hash include is the preprocessor directory. Then it includes hash include conio dot h console input output header file. It includes two functions that is get ch and clrsr. io stream, it includes two different objects. That is I see out and scene. See out is with the insertion operator and scene is with the extraction operator. Then void main function, void is the return type and means the function from where the actually the program execution starts. Now integer and sum equal to zero i equal to one integer n is nothing but I want to, what is the n value? It will be up to 11 digit and some equal to zero is the initialized value. I want this initial value to be one. So on that condition, I have to sum equal to zero and i equal to one is the starting value from where the, you can start with a one or zero, okay? Then afterwards see out, enter the n, okay? See out, there's a two, there's a operator called double lesser than operator, okay? That is called insertion operator. What does it does is whatever the string is after that operator, it will take it and put on the screen. Then there is a scene. Scene is a defined object for taking the input values. That is double greater than. It will take the input value, what are the user enters from the keyboard and inserts into the particular identifier called n. Now, while i less than or equal to n, so i value is one. Which is less than or equal to n is value is 11. So it will one less than or equal to 11. It's true condition. So then it will check for the odd number. Whether it is an odd or even. If it is odd, then only it has to calculate the number of some of the series. If one modulus of two is not equal to zero, it's true condition. So it will enter into the loop and it will calculate the sum equal to sum plus i. That is zero plus one equal to one. So afterwards it will increment the value to two. So two is less than or equal to 11. It's a true condition, okay? When two is less than or equal to two is a true condition, then it will come to the if. That is if decision control structure, okay? Two modulus of two is not equal to zero. Is it true? No, it's a false. It's equal to zero. Two is exactly divisible by two. So it is an even number. So it will not enter into the loop. And the sum of the series will be the same. Sum equal to one, okay? Now, once again, the i value will be incremented to three. Three is less than or equal to 11. It's a true condition, exactly. Now, three modulus of two is not equal to zero. Yes, it's true, okay? It's an odd number. So it will calculate this odd number for this. What was the previous sum? Sum equal to one. One plus whatever the three value. One plus three will be four. And this will repeat. And then it will display the sum of what are the numbers statement. Get CH to display the output on the screen. Input enter is n equal to 11. Output will be 36. So this is the table. Sum equal to zero and sum plus i, okay? So sum equal to zero, we have calculated one, okay? Then for the sum, for the next value of i, that is two, okay? Two is the false condition because it is perfectly divisible. It's an even number. The sum will be constant. For the three, it's a true condition. Three is not divisible by two. It has a remainder of one, okay? So it is an odd number. So then the sum value, what is the previous sum value? It was one. So one plus three will be four. Four, again, four will be a false condition, okay? When it's a false condition, it will, the sum will be as it is in the odd sum. That is four, okay? For the odd number, it will calculate the previous sum value. That was four plus five, nine. For six, it's an even number. It's a false condition. Then the sum will be obviously nine. Then for seven, it's a true condition again. So what was the previous sum? It is nine, nine plus seven equal to 16. For eight, it's an even number again. It will be a false condition. So the sum value will be remain constant. For the nine, that is an odd number. It will calculate the previous sum value plus i value. That is 16 plus nine equal to 25. Then afterwards, it will go to the next condition that is 10. 10 is an even number, okay? It's a false condition. So the sum value will be constant. Then for the 11, it's a true condition. So it will be 25 plus 11 equal to 36. So these are the references. Thank you.