 Hello friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain the difference between for why and do why. So I have divided this into three parts. First, I will be explaining for, second, I will be explaining why and third, I will be explaining how to use do by you. And all three loops will be related to C programming. So before starting, I want to share one brief information. So if you go to the detail or description of this video, you will find links of various playlist related to various programs. So do watch them. Now coming onto the topic. So first I'm going to write syntax and example of for you, then why and then do what. So if we talk about the syntax of for, so for is a keyword. Then you need to write initialization. Then a semicolon. Then you need to put a condition again semi-pulling and then you can put either increment or decrement. Then you can open curly days and here you can write the statements that you want to repeat and then you can close this. Right. So these are three important parts which are required for each and every loop. So first is initialization. Second is combination. And if you have more than one statements, if you have more than one statements, those you want to defeat with a loop, then you can enclose them within curly pieces. If you have only one statement to be repeated, then these curly pieces are optional. Right. Now one example. So let's say I am initializing a variable I with one termination condition is I laser equals to five and I am incrementing it by plus plus. Then I want to print my name, my first name only. So this way I am writing it. And here you can see I have not used curly ways because this time for loop is repeating only one statement. If I have one more statement, then I need to use curly basis so that I can put those two statements. Like so first let's understand the rotation cycle so that you can know how for loop executes. So first of all this initialization takes place. Then it checks the condition. Then the statements which are written are executed and then control will transfer to this increment or decrement part. Now after increment or decrement control don't go here. It automatically goes to the condition. So this initialization process is one time process. So your loop always initializes once and the meaning part combination condition statement execution and increment or decrement. They repeats until this condition is right. Now if I want to like one more written statement. So here I can do this like I am adding my last name as well. So this time I need to group them into. So if you have more than one statements that you can group them into early basis. If you have only one statement then only this is optional. You can use it or you can avoid it. So this is the syntax and example of one loop. Now I'm coming to why and then I will be explaining to why. So for my first time writing the syntax. So here we use initialization. Then a keyword why inside this keyword. Within parents is we need to write condition and inside this condition. We need to write statements that we want to repeat and then. You can write increment or decrement part. Right. So if you if you want to convert this example with why you so here you can see initialization. Condition and increment decrement both are available on separate places. So in real time implementation there might be possibilities like you need to implement initialization combination condition and increment decrement on separate places. So in that case you can prefer why you and if you have all three things initialization conditional increment decrement. In a single line that you can use a fall. This is the basic difference between for and why otherwise their rotation cycle is safe. So if we see the example, so first we need to initialize I equals to one. Then here you can write the condition like this and inside. This is you can write the statements as well as increment or decrement. So let's say I'm writing. Great. It will print my name. Then I plus plus and then I'm closing this. So here you can see this I equals to one is above the loop. So it is first statement and control will transfer to this condition checking if condition is true. Then this statement will be evaluated then this increment decrement will be performed and again comfortable to this condition. So this way we implement why you so I hope you understood the difference rotation cycle is same rotation cycle is saying initialization happens only once in both the cases and condition statement evaluation and increment decrement repeats till the condition is true. The only difference is placement of these initialization condition and increment decrement. So here we put them together, but in case of why we put them separately. Right. Now third comes do why so do why is a little bit different with foreign mind. So in case of foreign mind you saw if condition is true. Then only we are entering inside the loop so that we can evaluate the state. But in case of do why condition is available at the bottom of the loop. So first you enter inside the loop, evaluate the statement and then check the condition. So in case of do why it executes at least once. So, so let's check its syntax. So it is very easy. First you need to use initialization then do then here you can write the statements that you want to execute then increment or decrement. Now we need to close this curly ways and after this you can write why and condition. And then so this way this is the syntax of do why. So here you can see first initialization takes place that we are entering inside the loop. Then we can write some statements then increment decrement will be performed and then condition will be checked. So till we reach to condition check so it execute its post rotation. Then if condition is true, then only it will repeat otherwise it will be. So you can say for this top tested for this top tested as well as while is also top tested. So both are top tested. So they enter inside the loop if condition is true by do why is considered as bottom tested right. And here you can use one more thing like these are entry control loops. For and while both are entry control loops and do why is exit control. So these are the basic difference between for while and do why. So I hope you understood all the differences between for while and do why. And now you can pick the suitable loop as per your requirement by implementing the C program. So I hope you understood whatever I explained in this video. If you want to watch more programming related videos you can open my channel, go to playlist and then you can find various programs related to programming. So do watch them. I hope you understood whatever I explained in this video. Thank you for watching this.