 So, you are given a value n some number n may be 125, 237, 12 whatever some number is given between 1 and n there are numbers odd numbers and even numbers. So, which will be the even numbers 2, 4, 6, 8 etcetera odd numbers 1, 3, 5 etcetera. Now, suppose some number n is given you have to find the sum of all even numbers n is equal to 13. So, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. So, you will have to set up an iteration to do this summation write a program to do this. As long as this condition is valid keep doing this again and again. This also says the same thing as long as this condition is valid keep doing this. So, what is the difference? I will difference. You first check the condition if it is true you do these statements and then go back. Is that clear? While condition means first you check condition if true then come in go back. If true come in go back when it is false you come out. What is the meaning of this? The meaning is first do this. If condition is valid go back again do this. So, the checking of the condition happens after the statement here it happens before this. So, what it means is the condition is false write at the beginning this will never be done. There is a difference depends upon what logic you have required in the program you can put and this is of course counting iteration. You set i to 1 check this condition do this check this condition do this but every time you do this. Let us see spend 5 minutes in writing this. This statement is called initialization this statement is the condition and this statement is increment. If I do not have this or this then this condition is exactly like why. So, what is the condition here? The condition is i less than equal to n. Exactly like why while condition keep repeating for statement also says for this condition keep repeating. There are two additional things given in this statement. There are two additional things given in this statement. There are two additional things given in this statement. There are two additional things given in this statement. Now, what it does? This statement will be executed before you start doing anything initialization will happen automatically this statement will do. Second in the while condition loop you will keep repeating after doing this one. In this also you will do that but before going back you will execute the. So, this is a more powerful statement it initializes the count for i equal to 1. This statement is executed here then it checks the condition valid Karo in valid false that is the second part which is like why. Third part is this specification this specification says what? i plus plus this is written at the end this statement will be executed every time after the iteration is over this will be changed. So, whatever statement you will write here it will be executed here. So, in the while and form this is the difference. There are two additional things in the form. It is yourself. It is called initialization and it is called increment. Now, see how it will work. This block is to be repeated so first it will start with i equal to 1. Let us say n is 4. So, is i less than equal to 4 yes it will come here it will do this once then it says i plus plus. So, it will come back again after doing this it will change i once. I will become 3 go up is 3 less than 4 yes come down again do this. So, it will come back again after doing this it will change i once i will become 3 go up is 3 less than 4 yes come down again do this i equal to i plus 1 i is now becoming 4 is 4 less than equal to 4 yes it is equal to 4 it will do this again. Now, when it does it comes here i will become how much 5 is 5 less than equal to n no. So, it will come out. So, that means this block will be executed for i equal to 1, i equal to 2, i equal to 3 and i equal to 4. This initialization is done only once at the beginning and the increment is done every time. Initialization is done only once increment is done every time. We can write anything whatever we write here it will happen if we write i minus 7 then it will do minus 7 then after that it will do minus 6, minus 5, minus 4. So, these values are upto you. This statement is not a fixed statement of c plus plus. You can write whatever you want. But if we have to count and iteration then what is the most natural way that i have to do it 4 times. So, count start from 1, do it from 1, do it from 2, do it from 3, do it from 4, it will come out. So, it will come out. That is why it is often written as 1 to n. Suppose we start from 0 here and we have to do n bar only. So, what do we have to write here? Either i less than equal to n minus 1 or I can also say i less than n. This will also do the same thing one of that. So, you can see for example if instead of writing for i equal to 1 i less than equal to n this, suppose I want to write y and I want to do this actually. Then do you know how I will write a program using y? I will write it like this. Since this is the y loop, but I want to do this. Now I identify that this portion is actually exactly like y. So, if I write in my program explicitly this statement, if I write in the beginning, then this will happen. Then I can write the y loop with it and if I write this in the y loop, then you yourself will be executed. So, the way to write this is let us say int n i input n. This is the value of n. Now I have to write this for like iteration while. Now I will say i is equal to 1 while i less than equal to n. Whatever statement is here, I call this statement as s. Now the for loop will do i plus plus on its own as I have shown here. But while there is nothing here, then I will write i plus plus on its own. Or if you want to be very specific, you can write i is equal to n. Now if I write it like this, then what does this mean? Suppose it is n equal to 4. So, let us execute this. How will this work? We write the value of i and count it as iteration. What is the value of i in the beginning? 1 is 1 less than equal to n and 4 is s. So, it will do s once. Here it is i equal to 2. This is while and it is back. Is 2 less than equal to n? Yes, I will do this again. Again i equal to i plus 1. This will become 3. Again while will throw me back. The condition is 3 less than equal to 4. Yes, it is equal to 4. I will still come down again. Do this once again. I will now become 5 because of this. Go back. Is i less than equal to n? No. Then what I will do? I will come out here. When I came out, how many times did I do this? Four times. The same thing I used to do with 4. I can write 4 while doing vile. I can write it in the vile form. But I will have to write this statement myself and I will have to write this statement myself. I will have to write both. If I want to do this by doing 4, then I will write it in n i c in n. Now I have to write all this. So, I will just write this now. For i equal to 1, i less than equal to n, i plus plus. This statement is s. That is all. Because i plus plus is written here, then I have to write this here. I equal to 1. I had written this before the 4 loop. Here, I had written it before the vile. Now this has come into the specification. It has come in that specification. It will be executed like this. So, these are exactly identical programs. Both are exactly identical behaviors. Both will work like this. Now you have got such a powerful construct. Now you can solve the problems of your life. You now have a powerful construct. So, solve this problem. Find the sum of all even numbers between 1 and n for a given value of n. Some value of n is given. So, if n is invalid, then output, deriving, and freeing will come. No, but what will the program do after this? The program starts from here, takes input. If n less than equal to 0, it has executed this statement. Now it has come here. After this, it will come out of here. It will come here. What do you want? If n is less than 0, then you have to do this. Otherwise, you have to do all this. You don't have to write anything big. It will be wrong. They have started something. That is why I am writing this whole question. They have done what? n by 4. Let's see what they are doing. What have they done? The formula, the sum of n natural numbers, how many are there? 1 plus 2 plus 3 up to n, which is n into n plus 1 upon 2. So, they have done that formula. So, n into n plus 1 upon 2, if it is 2 plus 4 plus 6, then what will be the formula? They have done that formula. They had written n upon 4 in the beginning. They have come again. They can't write it up or down in the computer. Then they have written it like this. But it has been wrong here. What has been wrong? See, from c plus plus, evaluate this expression. First evaluate the right-hand side. n divided by 4. What else? What do I do? Syntax error. And it will not tell you that a multiplication of plus symbol is missing. It will give you some tail errors, which you will not figure out. Never ever write an expression in a high. Never ever. And between two operands, there must be an operator. He made the same mistake here. If n by 2 is not equal to 0, he wrote n minus 1 by 4. Again realize, though, aisa nahi chalega, he said n minus 1 by 4. But again, here what? And here what? So, you see, a small mistake can undo your activity. The problem is you are not using iteration. You are using a formula because you know the formula. The question here is that you have to set up an iteration. You want to learn iteration. The test is ke liye nahi ke aapko long formula malo mein ke nahi. Ye programming ki test hai, maths ki nahi. And programming ki test mein, ye likhah nahi nega ke iteratively solve karo. Lakin aapko iteratively solve karna chahiye. Weise ye uttar sahi hai ya galat hai, bada maske leke. Dhusra, ek baar ye condition test chek kar liye aapne. Fersi dubar aakno chek kar rahe. Kya isko, iski jage aap khali else nahi likh sakte thi? If this condition do this, as do this. Think about it always. Don't ever say if condition do this, if condition do this. So, you have to check either odd or even. You are doing it correctly. Lakin sahi usko e4 else mein likhah, come second. Chaliye dhusra yeh dekhtein. Yeh mein int mein wagare nahi likhta hoon. Yeh dhusra bhi sahi hai, jo vile kar ke likhah hai. Isme khali ek garbar ho bhi thodi. Yeh dekhtein yeh program dekhtein. Sahi hai nahi hai. Yeh kya kar rahe hai? Samko zero initialize kar diya. Then he is reading N. Now, he is setting up an iteration by counting. Usko kahan se kahan tak jaana hai? One se leke N tha. Toh apna wo, usne bakaid accounting lekaya hai. One, two, three, four, five, six, seven, eight, nine, N. Jitna bhi N, one thousand, two thousand hai karte jao. Toh yeh jo andar jo poora ka poora likhah hai, yehahan se leke, yehant hai. Yeh sab hissa, itti baar run hoge. Pehle i ki value one hoge, phir two hojai ki, three hojai ki, aur N hoke bhi poora karegi. Abhi usko kya chee jayaad karne, usme se odd number add nahi karne. Even number add karne. He has to add only even numbers, not odd number. So, what he is doing is, every time he is examining the value of i. Whether i modulo two is zero or not. If i modulo two is zero, what it means? It is an even number. Then he adds. If i modulo two is not zero, it is not even. He will only come here and automatically we will go there after increment. So, he will count one, two, three, four, five, but he will add only two, four, six. Do chaar, chhe khali add honge, ek teen paanch add nahi honge. Isme ek karbar hai, yeh jo comparison jo kya hai. Jab kondition likthe hain bracket me, while ke liye, for ke liye, ya if ke liye. Jab bhi comparison karthe hain, to kisi bhi do cheez ka comparison karne ke liye, agar equality comparison karna hai to equal, equal likna pao. Jab assignment karthe hain, sum equal to zero, sum is equal to sum plus i, i equal to one, yeh assign karna hain, hum lo vali, usse main ek equality. So, one equal to symbol means assign a value to left hand side name. X equal equal y means check, test, whether x is equal to y or not equal to. X equal equal y ka matlab ho, compare karo, x or y. Aur x equal to y ka matlab ho, y ki jo bhi value hain, wo x ko assign kardo. Boat sara ke donon. Ek comparison hain, dosri assign main. Tige. Yeh, ino ne virkul kareeb kareeb assign likha hai. Lekin ino ne indentation thi kya hai. Aapne yeh sabi jo theh wo ek line mein likhe hai. To yeh sabi jotha hai, if kaan se shoroh ke khatam ho raha hai, for kaan se shoroh ke khatam ho raha hai. To likthe se main agar aap sentences ko daba ke likde, to baraabar shoron mein agar hai. Yeh dekhe, yahan se for shoroh hoda, yahan khatam ho raha hai. Yahan se if shoroh hain, yahan khatam ho raha hai. If ke bech me jobi statement hain je, right mein daba ke. I percent 2 equal equal 0, bilkul sayi likha hai. Ish program ko analyze karte hain. Inko yeh to pata hai ki iteration karna hai, I equal to 1 to n. Ino ne for use nahi kya hai, while use kya. Wo bhi tige. Ino ne shorup kya, I equal to 1 se, for I less than equal to n. Aur yeh tab tak karte jayin ke. Aur ino ne yahan I plus plus likde hain. Yahan yeh n baar execute ho jayega. Har baar ho yahan aate, to I percent equal to equal equal 0, check karte. Yahan yeh if statement tabhi sach ho gha, jab even number ho gha. Yeh ish ke baat kya karne hain. S is equal to I karde hain. To har baar jab yahan hain ke, S ke value I ho jayegi. Har baar. Kya har baar aap karna chayenge? S ke value I hai? No. S ke value I se bundi chahiye. Yeh statement sahi hai. Sikin yeh statement se kya hoa? Isme ek aur bhenkar anarth hai sa ho gaya. Yeh yahan pe ino ne brass nahi dala. Aur isska brass bund nahi kya. To yeh tino jo statement hain, yeh if ke saath nahi kue. Bale aap nahi aap nahi aap nahi aap nahi aap nahi aap nahi aap nahi aap nahi aap nahi aap nahi aap nahi aap nahi aap nahi hain. Pichaah hasdake likh diya. C++ ko iss kesa likh hain se patlabh nahi. If you want all these three statements should be executed only if I is even then you have to put this like this here instead he has got this here and he does not have this here. You know what it means? The violence here. If statement starts and because it is not written, it will be just S equal to I. The rest of the statements will be executed every time. So this is wrong logic. How will logic be correct? How will logic be correct? That we don't want to write for, we want to write for while. I is equal to 1, that is also correct. While I less than equal to n, that is also correct. Is I even, I percent 2 greater equal equal to 0? Yes. Then that's all. But there is a problem in this. What is the value of S at the beginning? Whenever you want to sum up, the value of S should be zero outside. Outside the iteration. So here it should be S is equal to 0. And what was one more thing? It has not been defined. So here it is written in S. Until it is not written, this statement has no meaning. And S is equal to 0 should be before vile, once. After that, after zero, it will be S plus 2, S plus 4, S plus 6. And whatever it is, it goes here. Now this if statement is done. If statement is done here, then you have to do I equal to I plus 1. That is after adding, before going back. And you are going back from here. That is why you have to open the vile. Is that clear? How you should write and what logic it means? This vile something, opening curly bracket and this closing curly bracket means whatever is written here is to be repeated. And what is to be repeated? Check if the value of I is even. If so, add it to I. Otherwise, don't add. Don't do anything. But in any case, change I to 1. Okay? They have done the same thing. But here they have used the for loop. They have written for I equal to 1, I less than. Now this is wrong. Can anyone tell us the statement? There are two mistakes. Three mistakes. One is common. One is equal to one is equal. And this one is not written like this. Because there is no symbol like this. But the big mistake is that they have written here if. Now see what is happening. S is equal to S plus I is okay. But what does S is equal to I mean? They execute it. They execute it for N equal to 5. Let's see what happens. Okay? Suppose N is equal to 5. Now here we will write the value of I and S. What is the value of S at the beginning? They have written 0 here. It is equal to 0. So the value of S is zero at the beginning. What is the value of I here? One is one less than N. We have taken N equal to 5. Is one less than equal to 5? Yes. I come in. Is one even? No. Forget it. Come here. Go back. I plus plus. I what happened? 2. Is 2 less than equal to 5? Yes. Come in. S is equal to I. I mean S is equal to S plus I. S is equal to 2 plus 2. How many are there? Four. S plus I. S plus I. I is equal to 3. 3 less than equal to 5. Yes. Come in. Not even. Come out again. Go back. I plus plus. What happened? Four. Is 4 less than equal to 5? Yes. Come in. Is 4 even? Yes. S is equal to? S is equal to I, which is 4. 4 is equal to S plus I. 4 plus 4 is 8. They had to add values. 2 or 4. The answer should have been 6. The answer is 8. Why? Why? Because S is an accumulator. S means you have kept a box. You will keep adding new values. You will not assign new values to it again. S is equal to I, which is the reason for this. You will remove it. So, let's see how this program works. Initially, it was 0. There was nothing there. When 2 came, 2 added in 0. S value 2 was there. Then 3 came. There was nothing in 3. Then 4 came. Even 4 added in S. So, 4 plus 2 is 6. Now, it is going the same. In an iteration, never initialize the summation variable. In iteration, do not give a fixed value by equaling summation. It will only initialize 0. It will only accumulate a new value. You have to remove this sum. Sum is equal to sigma 7 times k plus 3 summation done from k to 5 to 20. It is exactly the same. But the expression is too big. You have to accumulate. It means sum of sigma. And what you have to add in it every time? 7k plus 3. This value will be 5 in the beginning. Then 6. Then 7. Then up to 28. We can do it exactly the same way by writing S is equal to 0. I will of course assume that I have declared in k, S and N. And I have done some c in. In fact, N is not required. Do you think this program will work? Just write it for k equal to 5. Start with 5. As long as k less than equal to 28, keep doing this. Every time change k by 1. Now, he is saying that there should be some input. The point is why do I need an input? I know that I have to sum between 5 and 28. So, I do not need anything. Suppose, however, the question was do it from 5 to N. Suppose, then I will have to declare an N here. And then I will have to say c in greater greater. Not only that, I will have to change the four iteration specification. What do I have to change in specification? I have to do sigma from 5 to N. This is what I am doing from 5 to 28. This is not good. Simple. So, how to accumulate? How to sum? Now, there are so many problems that have been put onto the homepage and also on the model. That problem will be seen on the homepage. And try to solve it. Solve it from all the iterations.