 Hello everyone. Myself, Mr. F. R. Syed. I work as an assistant professor in the department of computer science and engineering at Walchin Institute of Technology, Sholapur. The topic for my today's lecture is while loop, basically while loop in C language. At the end of this session, the students will be able to explain the basic working principle of the while loop and apply the while loop for a given problem statement. Now, in this video lecture, we will be covering the topics like introduction to while loop followed by the syntax and the working of while loop, then a comparison between the while loop and the for loop followed by an assignment for the students based upon programming. Now, these are the types of loops in C language. The for loop, the while loop and the do while loop. So, in the previous lecture, we have seen the for loop. Now, this time we will see the while loop. Now, it is often the case in programming that something needs to be done in a fixed number of times. Like for example, calculating the percentage of students in a class. For example, 60 students. Now, a while loop in C programming repeatedly executes a block of statements as long as a condition is true and the loop execution terminates as soon as the condition becomes false. So, for the loop to be going on, the condition needs to be maintained as true. This is the general syntax of the while loop. In this, we have the keyword while used followed by the condition. Now, as long as this condition is true, the loop executes. Now, after this condition is true, the control of program execution enters over here. The first statement is executed, then the second statement is executed and so on up to the last statement inside the loop. After that, once again the control is transferred to the condition part and if it still holds to be true, then once again we have the same statements getting executed from within the loop. So, in the while loop, the condition can be any expression and any non-zero value is considered as true. So, that means a zero value indicates false value. The loop will iterate while the condition is true and when the condition turns out to be false, the loop terminates and where does the execution control get shifted to? It gets shifted to the line immediately following the while loop. So, that is the point where the control would be transferred. And the most important thing inside a while loop is the increment or decrement of the loop counter. Now, the increment or decrement of the loop counter that is the iteration part, it is generally taken as the last statement inside the loop. Now, care should be taken to avoid an infinite loop. Now, what exactly is an infinite loop? An infinite loop is a sequence of instructions which loops or executes endlessly meaning there is no point where the execution of the loop gets terminated. Now, why does this exactly happen? The reason could be either absence of terminating condition. That means a user may have forgotten to include the terminating condition or the second reason could be unreachability of terminating condition. That means the terminating condition is written in such a place where the control does not get. Now, infinite loops generally occur due to improper programming style of the programmer. So, in order that infinite loops should be avoided, a programmer has to follow some standard programming style whenever he is dealing with loops. Now, next we will compare the two loops that is for loop and the while loop. Inside the for loop we have three sections initialization, condition and iteration and then we have the block of statements inside the for loop. Now, if I have a code with for loop being used and if I want to convert it to a corresponding while loop, how can I do it? So, the first part of initialization is written in case of a while loop just above the while statement at this point. After initialization, the condition is written inside the round brackets following the while keyword. So, this condition part comes over here in this while loop. Then the block of statements are written inside the curly braces and the last and the most important one the iteration part of the for loop is taken as the last statement within the while loop. So, that indicates first of all all the statements in the block need to be executed and then the iteration part is executed and after that the control returns to the condition part and if it is true once again these things go on continuing. So, this is how a while loop is different than a for loop. Now, next we have a sample program to display the whole numbers up to number 5 in descending order. So, what we need to do is we need to start in the backward direction. We need to first of all start with the number 5, then display 4, 3, 2, 1 and of course, at the last 0 because we know whole numbers start from number 0. So, what could be the code as of course, the first line hash include stdio.h inclusion of the header file. Then we have the main function starting with the curly braces and then a variable k is declared and k is initialized to 5. Now, we are going to deal with the while loop and inside the while loop the condition is taken as while k is greater than equal to 0 perform the execution of the statements within the loop. Now what are we going to do as long as k is greater than equal to 0 print f percentage d and percentage d is replaced by the value of k. So, at the first iteration k value of 5 would be displayed then k is decremented value becomes 4 once again the condition is checked still 4 is greater than equal to 0. Therefore, once again the control is transferred inside the loop then 4 is displayed then it is decremented to 3 and so on in this way it ends at the point where k value is less than 0. So, that could be the terminating condition. So, here k minus minus works as the iteration part and as of course, the end of the program with return statement return 0 and this curly brace concludes the main function. Now, next the students are expected to think and write the answer to the following question. Write a C program to find and display the sum of first 10 national numbers. We know national numbers start from number 1 and first 10 numbers meaning up to 10 1 to 10 would be the numbers whose sum is to be calculated and displayed. So, now pause the video and write your answer ok. Now, the C program to display the sum of first 10 national numbers we have the code as first of all inside the main function the variables of k and sum being used sum initialized to 0 k initialized to 1 and while k is less than equal to 10 we have sum equal to sum plus k meaning when k value is 1 the value of 1 is added to sum then k is incremented and then k value is checked whether it is less than equal to 10. If it is so, it is added to sum and then in this way all the numbers are added and at the end we have sum equal to percent h d that means, the value of sum is displayed as it has been calculated. Now, these are the references for the video lecture. The let us see book of 13 edition by Yashwant P. Kanatkar and then the references of ttwelspoint.com and program is dot com. Thank you.