 Hello everyone, myself, Mr. F.R. Sayed. I work as an assistant professor in the department of computer science and engineering at Walgen Institute of Technology, Sholapur. The topic for my today's lecture is nested loops. So, basically we are going to cover nested loops in C language. Now, at the end of this session, the students will be able to explain the tasks performed using nested loops and then apply suitable nested loops for a given problem statement. So, in this video lecture, we are going to cover the topics of introduction to nested loops followed by a real world example which is then followed by the types of nested loops and then a sample program followed by an assignment for the students. Now, sometimes there may be a situation where there is a need to iterate a single or a set of repetitive statements for a specific number of times. Let us take a real world example of this. Suppose that there are n compartments in a train and every compartment has a maximum of m seats. Let us try to imagine the work or the job of the ticket checker. The ticket checker may need to check the ticket for each passenger of each compartment. Now, this situation is well handled using nested loops. Here, we have a small code explained in terms of a real world situation where the job of the ticket checker is described. So, we can see two loops, one inside the other one. Now, this is the outer loop and this is the inner loop. Now, for each compartment in the set of compartments, we are going to check for each seat in a particular compartment. And for each seat in a compartment, the ticket checker is going to check the ticket of the passengers on that particular seat. So, this process goes on, first of all, for one compartment and when one compartment is over, the next compartment is taken into consideration and the same process continues. And in this way, the entire task of checking the ticket of each and every passenger on each and every seat of each and every compartment is handled. Now, C language allows the programmer to use one loop inside another loop. Now, such loops are called nested loops. Now, while loops and for loops can also be nested like the way if statements are nested. So, similar to how if statements are nested, we have nested if statements. The same way we can have nested while loops, nested for loops and so on. The basic use of nested loop is to include one loop inside another loop and for a specific value of the outer loop counter, the inner loop will iterate for a particular number of times. Now, any number of loops can be defined inside another loop and we can have any number of nesting level, meaning nested loops concept is not just restricted to two levels, it may go beyond that also. So, we can have one loop nested into a second loop, which is nested into a third loop and so on and this may extend as per our need. So, that is the flexibility provided by the language and the last point, any type of loop can be put in another type of loop. So, even there is no restriction on how nesting of loops is to be done. Now, we move on to the types of nested loops. The following is the syntax for a nested for loop. Now, we see this is the outer for loop, where we have the three sections of the for loop of initialization, condition and iteration and inside this for loop we have a second for loop. Now, this for loop is called as inner for loop and inside this inner for loop we have the statements associated with the inner for loop to be executed and after execution of the statements in the loop, the inner for loop will terminate and then the remaining statements of the outer for loop are executed. Now, this happens for every iteration of the outer for loop and thus these nested for loop works according to the requirement of the application. Now, next we take the nested while loop, the following is the syntax. This is the outer while loop and inside that we have the inner while loop. So, once the control is transferred to this inner while loop, the statements associated within that block would be executed and when this inner while loop terminates the remaining statements of the outer while loop are executed and then the iteration goes on containing as per expectation. The third type of nested loops would be a nested do while loop. Here we have first of all the outer do while loop beginning with the do block. Then we have the statements associated with the outer do while loop which would be executed first and after completion of these statements we have the inner do while loop where first the do block would execute first and then the while condition of the inner do while block would be tested. Once this do while loop terminates the control then transfers to the while condition of the outer do while loop and this goes on containing as long as the condition holds true. Next we have a sample program, a C program to display all the devices of the numbers from 6 to 10. The code as we can see is the first line inclusion of the header file stdio.h then we start with the main function and inside the main function we declare some variables and then we have the outer for loop where it iterates from value of i goes from 6 to 10. The outer for loop gives us the number whose devices are to be found whereas the inner for loop it finds the devices of the number being taken in the outer for loop. So first of all the number would be displayed and then this loop actually checks what are the devices of the number taken in value i and if i mod j equal to 0 means i is divisible by j and if that is so the j value is printed meaning this is a divisor. So this loop goes on continuing as long as we have the devices for the outer number and the outer loop will tell us what numbers devices we are calculating. Next the students are expected to think and write the answer to the following question. So write a C program to display the prime numbers up to 10. So now pause the video and write your answer. So now we have the C program to display the prime numbers up to 10. Now what exactly is a prime number? A prime number is a number which has only two devices that is the number one and the number itself. So we are going to start with the code. The first line is the inclusion of the header file stdio.h then we start with the main function then the declaration of the variables that we require. We first of all take the outer for loop in which i value tells us the number which is to be checked whether it is a prime number or not and inside that we have the inner for loop and the inner for loop actually checks whether the value of j does it divide the value of i meaning is j a divisor of the i value being considered. So for that inside the for loop that is the inner for loop we give the condition as if i mod j equal to 0 it means that i is divisible by j. So in that case we break the loop and that number is not considered but if this loop goes on executing and terminates at the point where j value becomes equal to i it means that no number from 2 to i minus 1 divides i. So if that is the case the loop terminates when j value becomes equal to i and if it is so we print f that the percentage d is prime that is the number is prime and thus we conclude with the program. Now these are the references for the video lecture. The let us see book of 13th edition by Ashwant P. Kanidkar and then the website of codeforwin.org for C programming and titeralspoint.com for C programming. Thank you.