All language subtitles for 23. Nested Loops - Print Right Angle Triangle Pattern - part 2 - Solution

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,670 --> 00:00:07,570 So let's start solving this exercise, and I'm just getting the template from the solution of the previous 2 00:00:07,570 --> 00:00:10,210 video where we talked about what was it? 3 00:00:10,210 --> 00:00:13,440 It was something like this or printing the following pattern. 4 00:00:13,450 --> 00:00:13,950 Right. 5 00:00:13,960 --> 00:00:18,450 Let's just make sure that it's exactly what I'm talking about. 6 00:00:18,460 --> 00:00:20,900 So let's go with the council. 7 00:00:21,190 --> 00:00:23,070 Let's use and equals the three. 8 00:00:23,080 --> 00:00:23,380 Yes. 9 00:00:23,380 --> 00:00:26,320 So we printed out one, one, two, one, two, three. 10 00:00:26,650 --> 00:00:31,530 And what we want to do in these exercises is the little we modify the pattern itself. 11 00:00:31,540 --> 00:00:39,370 It's still going to be a right angle triangle, but the pattern of the values at each line is going 12 00:00:39,730 --> 00:00:41,200 to be slightly different. 13 00:00:41,950 --> 00:00:47,620 So here we have the template of the code from our previous exercise. 14 00:00:48,070 --> 00:00:55,360 And let's simply start thinking about what should be modified in this solution so that this way we may 15 00:00:55,360 --> 00:00:56,890 satisfy these conditions. 16 00:00:57,880 --> 00:00:59,170 So what will happen? 17 00:00:59,470 --> 00:01:06,730 We need to print the value of one just one time on the first row and the value of two, two times on 18 00:01:06,730 --> 00:01:08,860 the second row and three and so on. 19 00:01:09,700 --> 00:01:14,680 So we need here, let's say that we have like I is already equals to two. 20 00:01:15,670 --> 00:01:18,010 And then in this case, we need to print. 21 00:01:19,000 --> 00:01:24,240 We need to be equal to to write in printed two times. 22 00:01:24,250 --> 00:01:32,290 So we need to print the value with say we need to print the value of I write because I equals to two 23 00:01:32,560 --> 00:01:35,740 and we need to run this operation just two times. 24 00:01:35,740 --> 00:01:38,280 So that's OK. 25 00:01:38,290 --> 00:01:39,730 We will run it time. 26 00:01:39,770 --> 00:01:42,940 So J no, it doesn't matter what is the value of J. 27 00:01:42,940 --> 00:01:46,030 Of course J will be will start from one. 28 00:01:46,150 --> 00:01:46,610 Right. 29 00:01:46,630 --> 00:01:51,590 That's the initialise phase and will run up to AI which is two. 30 00:01:51,610 --> 00:01:56,260 OK, so J will run two times and we will print the value of AI. 31 00:01:56,620 --> 00:01:57,660 OK, ok. 32 00:01:57,670 --> 00:02:03,010 I think we are getting closer so I'm not sure that that's the final solution. 33 00:02:03,010 --> 00:02:05,530 But let's try to build and run it OK. 34 00:02:05,890 --> 00:02:07,210 And see what happens. 35 00:02:07,480 --> 00:02:10,440 OK, so that's also one way of working. 36 00:02:10,450 --> 00:02:16,840 It's not usually recommended and like to build and run it when you are not sure for a hundred percent 37 00:02:17,140 --> 00:02:19,690 that that's your optimal solution. 38 00:02:20,020 --> 00:02:26,470 But sometimes when we have very similar exercises, for example, like this exercise is very similar 39 00:02:26,470 --> 00:02:32,200 to the previous one, then in this case, I'm I'm giving you the option to to do this. 40 00:02:33,040 --> 00:02:34,750 So let's run here three. 41 00:02:35,140 --> 00:02:41,380 And yeah, basically we can see that everything works correctly and we have here the value of one, 42 00:02:41,380 --> 00:02:42,610 two, two, three, three, three. 43 00:02:42,610 --> 00:02:49,150 And let's just make sure that if we used different values, everything seems to be working correctly. 44 00:02:49,160 --> 00:02:51,220 So one, two, two, three, three, three. 45 00:02:51,490 --> 00:02:56,170 And basically, yeah, everything seems to be working just perfect. 46 00:02:57,190 --> 00:03:04,900 So, yeah, another option that some of you probably thought about is maybe to use it for a loop in 47 00:03:04,900 --> 00:03:07,780 inside of these for a loop to use a while loop. 48 00:03:08,500 --> 00:03:10,390 So that's also an option. 49 00:03:10,390 --> 00:03:12,900 And let's think about how it can be used. 50 00:03:13,240 --> 00:03:19,900 So we need to print AI the value of ay ay times. 51 00:03:19,900 --> 00:03:20,170 Right. 52 00:03:20,170 --> 00:03:26,020 So we can say that let's say J equals to J equals to. 53 00:03:26,080 --> 00:03:34,990 I write and we will say as long as J is greater than than zero, then in this case we will print the 54 00:03:34,990 --> 00:03:36,600 value of Pi. 55 00:03:36,610 --> 00:03:41,080 So let's go like this in here, specify the value of AI. 56 00:03:41,650 --> 00:03:46,420 So let's see what happens and let's go with the value of five. 57 00:03:46,930 --> 00:03:48,310 Then we have a problem. 58 00:03:48,820 --> 00:03:51,220 So let's find what is, what is the problem. 59 00:03:51,520 --> 00:03:53,800 So it's probably an infinite loop. 60 00:03:53,800 --> 00:03:54,220 Right. 61 00:03:54,220 --> 00:03:56,620 And we know that in this case. 62 00:03:58,360 --> 00:04:06,790 In this case, we know that the value of G will be forever greater than zero and the slope will be executed 63 00:04:06,790 --> 00:04:07,270 always. 64 00:04:07,510 --> 00:04:11,620 So what we need to do is just to try using J minus minus. 65 00:04:11,770 --> 00:04:13,960 So let's build and run it once again. 66 00:04:14,740 --> 00:04:19,750 Click on this button and let's see what will happen. 67 00:04:19,780 --> 00:04:23,900 So now let's go like five in here. 68 00:04:24,070 --> 00:04:24,880 There you go. 69 00:04:24,910 --> 00:04:28,420 You can see your solution on the screen once again. 70 00:04:28,420 --> 00:04:33,850 Let's run it again with another value and see that it's working exactly as we expect. 71 00:04:34,570 --> 00:04:34,960 Yeah. 72 00:04:35,140 --> 00:04:39,100 Basically, that's the pattern that we expected it to be. 73 00:04:39,100 --> 00:04:42,610 And you guys, this is it for this video. 74 00:04:42,610 --> 00:04:50,080 We introduced the concept and talked about the concept of for loops inside of four loops, basically 75 00:04:50,080 --> 00:04:51,430 using nested loops. 76 00:04:51,760 --> 00:04:57,700 And we also saw how we can take an inner loop of while into use it inside for a loop and how we can 77 00:04:58,030 --> 00:04:59,970 take it for a loop and use it inside of an. 78 00:05:00,330 --> 00:05:05,250 For aloof and also there is no problem using a while loop inside of a while loop. 79 00:05:05,730 --> 00:05:13,950 But one thing that you need to take to to bear in mind is that there should be some reason, some logic 80 00:05:13,950 --> 00:05:15,600 behind this usage. 81 00:05:15,640 --> 00:05:24,270 OK, there there will be no not all the exercises require you to use nested loops, but some of the 82 00:05:24,270 --> 00:05:30,820 exercises will require you this knowledge and understanding of using nested loops. 83 00:05:31,230 --> 00:05:34,770 So once again, make sure you understand everything. 84 00:05:34,980 --> 00:05:38,420 And if you still have some questions, feel free to ask them. 85 00:05:39,060 --> 00:05:41,390 And yeah, until next time, guys. 86 00:05:41,400 --> 00:05:42,030 Good luck. 7723

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.