 Hello friends, I am Sanjay Gupta. Welcome back on Sanjay Gupta Tech School. So, you are watching Sea Language video series. And the lecture number of this video series is 14. And the topic we are going to discuss in this video is Naster Loops. So, we will design some patterns like this. So, first of all, we will design this pattern. Then apart from star, we will print digits and alphabets. Then we will convert this design into this water image. Then this mirror image and then this water image. And these are my information. You can contact me for online classes or if you have any doubt, you can discuss it with me. And in the previous video, I completed the Dubai Loop. So, I hope you liked it. So, now you can watch this video. If you want to follow the entire video series, I have put the playlist link in the description of this video. So, from there, you can follow the entire video series. So, first of all, let's see a syntax in which the nested loop works. You will understand that. So, this is a highlighter for me. So, this for loop implemented is called outer loop. And I have implemented one more loop in it. That is inner loop. So, what will happen? First of all, the outer loop will initialize. That means the value of i will start at once. Then i loop will check its condition. If this condition is true, then the control will be transferred to the inner loop. So, the inner loop will initialize. It will check its condition. So, the condition of the inner loop is true. So, the value of i and j will be printed here. So, i is 1 and j is 1. So, it will be printed on the screen. Then j will increase itself. So, j will be 2. And then the inner loop will check its condition. So, when the control is transferred to the inner loop, then the inner loop will continue until it falls. Okay? So, j will be 2 here. And j's condition is true. So, the next output will be printed as 1, 2. So, you can see that when the inner loop will be 5, then the value of i will not increase. And j will be 1, 2, 3, 4, 5 printed. Then when the inner loop will terminate, then this i will be plus plus. So, i will be 2. Again, i will check its condition. So, if the condition is true, then the control will go to the inner loop again. j will reset from 1. And again, this loop will go 5 times. So, this time it has been 2. And j will repeat 5 times again. So, the output will be 2, 1, 2, 2, 2, 3, 2, 4 and 2, 5. So, in this way, if the outer loop is going once, then the inner loop will complete its rotation cycle. And then this process will continue. So, when the inner loop will check its termination condition and this will be false, then the outer loop will increase. When the outer loop's condition is false, then this will stop. So, let's implement this once practically. So, let me remove this code. So, now we are seeing the nested loop example. So, here I am declaring two variables i, j. So, inner loop, sorry, outer loop, once it starts, i less than equals to 5, i++, then in this, inner loop starts, j equals to 1, j less than equals to 5, j++. And in this inner loop, we are writing printf, backslash n, %d, %d, i, j. So, when the outer loop will set its value to 1, then the inner loop will execute 5 times. So, the first output will be 1, 1, 1, 2, 1, 3, 1, 4, 1, 5. When the inner loop will complete, then it will be i++, it will be i2. Again, if it goes 5 times, then the output will be 2, 1, 2, 2, 2, 3, 2, 4 and 2, 5. So, now we have to check whether the output is printed or not. So, you can see that the output is available in front of you. 1, 1, 1, 2, 1, 3, 1, 4, 1, 5. Then 2, 1, 2, 2, 2, 3, 2, 4, 2, 5. Then after 5 times, if it will increase again, then it will be i3. And it will start again from 1. So, in this way, 25 outputs are printed. So, the outer loop is 5 times, and the inner loop is 25 times. So, this is the nested loop formation through which we will print those patterns. Before that, let's take one more example. Now, I will use if else in this combination. And you have to identify its output. So, here I am applying if i equals to j. So, if this is true, then we have to print 1, otherwise 0. So, I have written printf1 else printf0. And when the inner loop is completed, then I am printing backslash for the new line. So, see what will happen in this. It will start from i1. It will check the condition. The condition is true. Then the control will go on the inner loop. So, now only this loop will work 5 times. And if it will check the condition 5 times, then the value of i is 1. And j will be 1, 2, 3, 4, 5. So, if it will match for the first time, then it will be 1 print. And if it will not match for the rest of the time, then it will be 4 times 0. So, in the first row, it will print 1, 0, 0, 0, 0. When the value is printed 5 times, then this loop will be finished. After that, what will printf do? It will print backslash and print. So, you can see that in the upper printf, there is no slash n. That means the output will be printed in the same line. And after that, it will be printed in the new line. Then printf will go after printing the new line on i++. So, now it will go on i2. Let me check the condition. Now, it will go again on jloop. Now, jloop will go again 5 times. And when jloop will go 5 times, then at this time, the value of i is 2. So, when j2 will be there, then it will match. Otherwise, no. So, in that case, it will be 0 print. So, first of all, it is i2. It is j1. So, if it does not match, then it will be 0 print. Then i and j, the next time it will be 1 print. It means, when i and j are equal, then it will be 1, otherwise 0. So, the diagonal positions will be 1 print. Otherwise, it will be 0 print. So, if we run this, then you can see the output. Here, the diagonal is 1 print. And the rest of the places are 0 print. And 5 outputs are coming in every row. 1, 0, 0, 0, 0. Then 0, 1, 0, 0. Then 0, 0, 1, 0, 0. So, this is how the output is being printed. So, the important role of backslash n is here. This is the important role. When you have to print 1 and 0, then you do not have to use the slash n. When the inner loop completes the cycle, then you use it. So, how does the nested loop work? You must have understood this. So, we will print this pattern. In the first line, 1 star, then 2 star, then 3, 4 and 5. So, we erase this. Now, this format will remain the same. Means, we have to use the print f slash n when the inner loop completes the cycle. Because in one row, we have to print many values. So, we do not have to use the inner loop with the print f. Now, the outer loop worked 5 times. The inner loop worked 5 times. So, we have to print 5 digits in every row. But what we have to do now? In the first row, 1 star. In the second row, 2 star. In the third row, 3 star. Means, 1, 2, 3, 4. So, who will get that value from i? So, here I am writing 5k place on i. And here I have written print f. And start. Now, see how this will run. It started from i1. Check the condition. The condition is true. Then, the control will run on j. It started from j1. Now, the condition of j loop depends on i. So, this time, the value of i is 1. So, how many times this loop will run? Once, the star will be printed. When this loop will be finished, the slash will be printed. Then, i++ will run. i will be 2. The condition is still true. Again, j loop will start from 1. And i will be 2. So, how many times j loop will be repeated? 2 times. So, it means, the rotation of j loop depends on i. So, the value of i will be repeated as much as j loop. Now, if i execute this by saving it. So, see this. In front of you, this pattern is printed. In the first row, it is 1 star. Then, 2 star. Then, 3, 4 and 5. Okay? Now, to make this kind of triangle printed, these two loops are fixed. You don't have to shake them. Now, suppose we want to make the pattern printed in some way. I will open a mood pad. We have to make the pattern printed in some way. In the first row, it is 1. Then, we want to print 2, 2. Then, 3, 3. Then, 4, 4. And then, 5, 5. We have to make some pattern printed in this way. So, I am here, %d, i. Now, see, I have printed the value of i here. So, when i is 1, j loop will be 1. Then, i will be 1. Then, i will be 2. Now, j loop is going on 2 times. And, how much is the value of i? 2. So, how many times will it be printed? 2 times. Okay? And, this is what we have to do. So, when you print i in an inner loop, you can see. 1, then 2, 2, 3, 3, 3, 4, 4, 5, 5. This way, the value will be printed. Okay? Now, you want to change this pattern and print it like this. So, in this case, if we print j instead of i, this pattern will be printed. See this. 1, then 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5. So, simply, i has been replaced by j. So, what is happening now? j's current value will be printed by hand. So, j's loop, how many times it is going on? It always starts from 1. It goes up to i. So, it will print 1 for the first time. When it rotates 2 times, when it starts from 1 and goes up to 2, it will print 1 and then it will print 2. Okay? So, the same format is there. We are just changing the print F and the new values are being printed in front of us. Now, we have to print the next pattern, which is this. 2, 3, then 4, 5, 6, 7, 8, 9, 10, then 11, 12, 13, 14 and 15. We have to print something like this. So, you can see in this pattern, digits are continuously increasing. 1, then 2, 3, then 4, 5, 6, then 7, 8, 9, 10. Now, for this, we have to use a new variable, k, which starts from 1. We print k here and we write k++. So, as soon as it is printed, it will increase its value from 1. And it will increase its value as the loop goes on. So, you can see in this pattern, this is the output in front of you. 1, then 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15. Now, if you want to print some space in between, you can add backslash t. So, when you run it, you can see that some space is being printed in the form of triangle. If you want less space, you can simply press space bar. If you want less space, you can simply press space bar. So, this is how you can design these patterns. So, you can make the format you want. I told you how to print stars and how to print digits. Now, we will talk about alphabets. Now, we will print something like this. a, then ab, then abc, then abcd, then abcde. First, we will print it. Now, we will declare a character variable here, ch, and initialize it with a. Now, if you look at this pattern, it is always starting with a. In the second row, it will go to ab. In the third row, it will go to ac. In the fourth row, it will go to ad. We have to increase it every time. Now, the format of the loop will remain the same. Now, we will repeat the time. The print we are going to do is ch. Because this is a character variable, we have to use the format specified. And we have to increase ch every time. Because after a, in the second row, after a, in the third row, c should be printed. So, it will increase it. Internally, it will go through the values. And if I initialize it here, the ch will begin with a. Because when we increase it, it will reach to ab. In the second row, it will print a. and reach to c. So, whenever you start an inner loop, you have to start ch. A variable. And a is a constant value. So, if you want to initialize it here, it will work. Everything else is the same. So, whenever the inner loop starts, ch will be set with a. And in the inner loop, it will print the values in a or ch. And then it will increase its value through a. So, let's execute it. A, ab, abc, abcd, abcd. This is how we print the loop. Now, we modify it. So, we have to print a. Then bb. Then c, c, c. ddd. ddd. Means, the same alphabet should be printed every time. So, we remove this. And we initialize a here. Okay? Now, what will happen is you have to start a once. Then you have to pay attention to the row. Means, in one row, the same value should be printed. And after that, it should increase. So, remove ch from here. And after this loop. So, when this inner loop continues, the same value of ch will be printed. And when this loop will end, then ch will reach the next character. And we don't start ch again and again. That's why we initialized it in the beginning. In the loop, ch will never be started from a. So, we had to print the same value. That's why we didn't increment it in the loop. We did it outside the loop. And we always have to increment it in the loop. So, we have to print ch again and again. This has to be initialized on a. Now, if we execute this so that the pattern will be printed, a then bb then ccc ddd like this. So, it's very simple. The format of the loop is the same. You have to keep in mind that how can we print here? Now, if I cut it and paste it here and initialize ch on top. या आर बार केक्तर प्रहवेंट हूँ जाएगा, बतल आग़्े अग़्े अपबेट प्रहवेंट होँ अग़्ेगा तो आब देखोगे कि आ दें भी सी बईन, दिएप गीच अझे चिज्टेग आ प्रहवेंट होँ एज्टेगा तो इस तरीके से बहुत सरे पैटन्स में आपको प्रिंट करना बताए, अब हम चलता है यस पार, तो अब यह जो पैटन अभी तक हम ने बनाए च्तार के दिजिट्स के अप्रबेट्स के उनको अगर इस फोम में प्रिंट करना है, तो कैसे गरेंगे, तो आपको क्या करना है तो आप दिख होगे गी वो, वोटर इमेच में प्रिंट जाए, ये दिख है, शुरू में पाच लाईन है, फिर शुरू में पाच आलफवेट, दें चार, दें तीं तो है, एक, चेगे, तो किसी भी पैटन को आप यस तरीके से गंवरत कर सकते है, अगर आपको स्तार प्र और नीक, नप्र स्लेएश बी, खमन्ट कर एक लाईन भाच यह कर सकते है, तो आप ये वी रहुज खर सकते हैं, और ये वी रहुज तो अब देखो मैंने सिर्फ फ़स लूप को चेंज किया बाकि सारी चीजे सेई में फिर भी आपका जो पैटन आप वो रिवर्स वोम में प्रेंट्गाए पैट्च्टार, फोच्टार, खीच्टार, तुच्टार, बान्ट्च्टार तो अब को शारी चीजे सेजे सेब रहेंगे छीक अब हम चलते है अगले पाटपे जो स्वियमें ये मिरड उग़े मिस प्रंट करानगे तो इस में अब देख सकते है, ये स्पेस भी प्रिंट होँगा उप अव में एक लूप और चलाँनेगे ब्रखया व्या हह Stars off अआ लुप परईगा प्र� princess लोग है आ� echoes 5 ाई plus plus इसे लուप लेहता करते हैं जे एकूल is to 1 ऩलिए जे अब दिखो of the ऐकमशको आन्लüst ऍो लास्टरो मेste इक ve space there're ौत उ --> उ उ उ उ अगर 3 योट्चार टीन, अगर 4 सपेशत्ये था वाहाने येसको में नोट पैड में पनाले भाखता है जब से लगाई आपको औरोचे ज़ाएज़्ाएगे अगर 1, 2, 3, 4, space & one-star त्ब योट्चार ऑगा एग पाथ सपेस था गगे और चार अप देख सकते हैं यहापे आमे चार उस्पेस प्रेर्ट करानां, आब नहीं मैंगब डश को स्फेस मानें, ठीकगे, तो रह में चार, तींए तो एक, शीवो, इस ठीके से क खिलोग जलाना, तो अब देख हो अम ख़ स्फ्रोपभ आग, आप पाच च्कर उस्पार यहांगं ये अपना आपना लूब होगया तो अप देखो आई वन है तो ये लूब चला 5-1 मतलब चार बर चार सबेच प्रिंट होगये फिर इस लूब पर आएंगे ये लूब कितनी बर चलेगा एक बर क्योगी के कान तक रिपीट होगया आई तक और आई है वन तो चार सबेच उपर वले लूब के प्रिंट की है और वन स्थार इस ने प्रिंट काजी फिर लूब आएंगे चलेगाएंगे फिर आई प्लस प्लस होगा आई अप उचुक आई 2 तो अब इस लूब को चेख करोग तो कितना या 3 अप बच्टम स्पेश प्रिंट होगर रहा है अब ये लूब कितनी प्रिंट नेगा तो आई की याई की वेल्ँ क्या है 2, तो 2 व़च्टार प्रिंट होगर जाएं। तो हमें यही करनाए वस फो में चार स्पेश के लिए चार तो आपको सिंपली बिगनेंग वाले लुप को दिक्रीजीं अडर में चलाना है, और ये अटर मेंटेक ली, जो आपका पाटन है वो वार्टर अमेच में प्रिंट तो जाए, ये देखे, अमें यही प्रिंट करना था, और यही आपके आपके अउपुट श्क्रींप पर दि आपको सर्फ अलपाबेट येजेट़ को चेंच करना हैtechn. आप सपोज ल्में दिजाट प्रिंट कराना है, मैंअ यह आई को प्रिंट कराना ही ता हुट तो अप देखो क्या होता है, ये देखें, 5 times 5, then 4 times 4, 3 times 3, 2 times 2 and 1, और स्पेस भी प्रिंट हो रहा है, तो मैने जो फस्ट देखान प्रिंट करने के लिए आपको स्थार, दिजित तो आप प्रिट स्प्रिंट करने का लोगिक बता है, तो पहली रोग, 1 into 2, minus 1, ये जो यहापर हम ने, i into 2 minus 1 लिए का है, तो i1 होगा, 1 into 2, 2 minus 1, मतलब एक स्थार. तो जब आई अगली बा तो जाएगा, तो यो जाएगा, 2 into 2 minus 1, मतलब 3, तो स्थार किती बार प्रिंट होंगे, 3 times. तो इस तरीके से हम ने, जो रो नमबर है आई, उसको 2 से मलटिपलाएगर के 1 से minus किया, तो अड नमबर सावेलिबलो जाएगी, और स्थार उसी अपकोडिएग बिंट होंगे. आब अगर उसी को वाटर इमेच प्रिंट करना है, तो आप इस को 5 से start करो, देटर ने एकवल सो भान, और मिझश मिझश बाख कि सावे जीजे सेझम रहींगी, तो अब इस को दिबर सोडर में प्रिट करना या जीस परीके से प्रिके. और से अपकोडिपलाएग के ये पैट्टन्स की ये पूरी वीट़्िएउ सीरी जो़ और बना रही है, यह पाटन्स के एक पूरी वीडियो सीरी जोर बना रगी है तो मैं उस वीडियो सीरीस का जो लिंक है वो भी देस्क्रप्षन में पेस्ट कर दोंगा ताकि आप अप अप यन पाटन्स के जो प्रोगान आप अप दीटेल में समच्छ्खाँ तो उस वीडियो में मैं आप को वन्टी एक बाटऩ् में बतावगाय में तो उस को भी जरु॥ से देक हैं ता कि आगे आने वोले सारे वीडियो स्वालो गर पाए तो आप आप आप जोबी बीटिटो डिस भीटीो सीटी जेचक आनगर देक आप को समच में आरहे होंगे आप लिंगस जोग़ा एह वो दिसक्रिषन मैवेलेपड है लिएटेो के उसको फोलो करे आप उंई कोई भी प्रड़म वो मु� systematic problem-um"- उझ खाह वो मुँँ से कमनिकेट कर सकते है the way you can communicate with me उसलके लिए इप खारे या वो मुझे। so thank you for watching this video