All language subtitles for 21. Nested Loops - Print Right Angle Triangle Pattern - part 1 - Solution

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
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
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

All right, so welcome back once again, let's just put it under here, OK?

So in this video, what we are going to do is to solve the previous exorcized.

The previous question that we simply have to print there right in your rectangle.

So that has the following pattern.

So, for example, an equals two three.

That's the value that we receive from the user.

In this case, we have to print these rectangles.

So one, two, and one, two, three.

OK, so I think the instructions are pretty clear to you guys.

And the one main thing that we have to understand is what will be the logic and how we should use our

C programming language to solve this exercise.

And what I suggest you guys is to start with the following idea.

OK, so let's start and try to do it with just using one loop.

OK, just using one for a loop.

So for I equals to one as long as I use less than or equal to n probably.

Right I plus plus.

So that's basically where a lot of students get stuck in.

The question that comes here is what should you use in these for a loop.

So we know that in the first, on the first line you should print one.

On the second line you should print one, two and then the third line you should print one, two, three.

But what how how can you express it here in the body of the loop?

That's a difficult question because we may use print if I but in this case we will simply print one

to three.

We we also, I don't know, do it like until it's minus one or a minus still.

But it will it will not solve our problem here.

So what should you do?

And basically my recommendation is to start thinking of additional loop of a nested loop.

So we will simply use this the variable of the variable.

I will use it as part of the outer loop, OK, the outer loop.

And we will also use additional inside loop that I will explain you guys in a moment.

Don't freak out.

It's OK.

Don't worry.

We'll simply use additional loop and for at least a little bit to create a temp variable, some additional

variable that we will call J.

So it will look like this.

So four J equals two.

One.

OK, let's say, OK, I'm just writing to some some option.

You will tell me if that's OK or not.

As long as J is less than or equal to and J plus plus and here will print the value of J.

OK, so what do you think will be printed in this case to the screen.

So let's build and run and see for first of all, let's see for ourselves what will be printed on the

screen and then make some conclusions.

OK, so let's insert, I don't know, three so you can see here.

One, two, three, one, two, three and one, two, three, once again.

So just to let you know how these nested loop works, basically we start from the outer loop with I

equals to one and we run the body of this loop three times for equals to one.

Four equals two two and four equals two three.

OK, so three times we need to run the body of this loop.

So one, two and three as long as I equals two, one, two and three.

And then on every duration of the outer loop we will execute this for a loop.

So we will execute this for a loop for I equals to one right.

I equals to do and I equals to three.

In what will happen inside of this loop, inside of this inner loop, we will also execute this print

command.

How many times how many times will do it.

Three times when J equals to one.

G equals to two equals to three.

So that's where we print one to three for the first time.

OK, so first iteration points one second prinsloo, third print's three.

But we are not done because we completed just one iteration of the outer loop and now we will come here

again.

I will be incremented and equal to two and we will execute the body of this loop once again.

And then the third time we will execute it once again.

So on every duration of the outer for a loop we execute of full loop of this scenario duration with

all the durations that print one, two, three to the screen.

So I hope that's clear in.

It's very important to understand this concept in once you know this much, let's start thinking about

how we can pretend like, I don't know, let's basically just add also additional linowitz and print

a percentage.

And so that this way things will be even more clear to you.

Of course, cynical and at the end.

So let's build and run it once again and see what happens.

Basically, what will be the shape of a pattern that we will get right now.

So three.

Oh, OK.

So now you can see that you print one, two, three, one, two, three, one, two, three on every

line.

So every line simply represents one iteration of the outer loop in every column represents one iteration

of the inner loop inside the outer loop.

So for that, let's simply change these variable and to be variable, I.

OK, and now let's build and run it.

So this case we will see.

Let me explain you guys everything in just a second.

So let's here is three and there you go.

There is your right angle, a rectangle pattern, just like we were requested and how it works basically.

So we start with I equals to one, OK, and we come here to this loop in this little we we we assign

the value of J to be equal to one and that's OK.

We print one to the screen, then we increment J by one J equals two two and we ask the following question

is two less than or equal to one is it.

No, of course.

So that's why we exit the inner loop and we simply print a new line.

Once we are done printing the new line, we come here to the outer loop.

We increment I by one and we have I equals to two.

Then we come to the inner loop once again, J equals to one.

So we know that J is less than or equal to two.

In this case, that one is less than or equal to two.

We print the value of one, then we print the value of two because J will be incremented to be equal

to two and two is less than or equal to two.

Right.

Because I equals to two.

We print the value of two and then when J goes to three, these condition returns, falls and we simply

print the new line.

Awesome.

So now the lasting duration we know that equals the three and that's how we do it again.

We simply execute the inner loop from one up to three.

So basically all that has changed is just this condition of J as long as it's less than or equal to

EI.

So let's build in running just to make sure that, for example, if we have, I don't know, ten value

of ten.

So yeah, you can see the exact pattern that you would want to see on the screen printed exactly as

requested.

So this exercise was completed successfully and I think you're making really good progress with the

material so far.

That's not a basic understanding of the inner for loops and using like a for loop inside of another

for loop.

But I think we've covered everything up pretty good.

And if you still have any questions, you may also use, OK, for example, just for your sake and for

your simplicity, just use some table and to draw like what will be the value of.

OK, let's say for I equals to one what will be executed J equals to one equals to two if it will be

executed will whether the condition, the result of the condition will be true or false.

OK, and simply running it or even on a piece of paper that will also be OK, just make sure that you

understand this concept completely, even watch this video again if it's necessary for you.

And yeah.

So as always, guys, my name is Vlad and really excited and happy to teach you these C programming

course.

And until the next video, I wish you good luck.

Practice a lot and we'll see you then.

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