All language subtitles for 2. Print from 1 to num and vice versa - 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

OK, welcome back to the solution that's first of all, to remove this myth that we do not actually

need it.

We used it in one of the previous exercises, but now we don't have any interest in any interest in

it.

So what we have tried to do in this exercise is simply to get some number gets done and then we should

print all the natural numbers from one up to these given numbers.

Right.

And on the next line, to print all the values from up to one.

Right.

Simply printing them vice versa.

So it will be like like that.

OK, so that's our task.

And we are going to do it using loops probably.

Right, because we are in the section of loops.

So let's create a new variable enum and as usual, print Afghans or and and then we are going to read

the variable number.

Let me just take this key word here and are using kind of function to read the number from the user

and story inside variable num.

Basically the first step is complete.

We have the NUM and now let's think about how we should implement and use the loop.

So basically, if we want to use the loop, one good way would be to use probably the for a for loop.

Right.

So if we want to use the for loop let's create additional variable called this variable I and this variable

will be used on every duration in our loop and also is our condition, so forth.

And I think enties not iis equal to zero because we already declared I.

So that's the initial phase of these for loop.

Let's just increase it a little bit.

And the condition is as long as I is less than or equal to num I plus plus.

So the question is if this statement is OK and why am I asking you this question.

Because if I start from zero.

OK, but we want to bring just the natural numbers without the zero then probably it will make sense

to start dying from one.

OK, so from one up to five included.

OK, that's the explanation of this condition.

So for I equals to one as long as I is less than or equal to num c++ on every duration and we are going

to print simply print f what are we going to print the value of I so percentage DB and basically that's

how we are going to do it.

So instead of these percentages we will use AI.

Right.

So let's simply try to build and run this program and see how it works.

So press build and run and hopefully everything is OK.

So let's see what happens here.

So answer now.

Why doesn't enter now.

So let's go with five.

So one, two, three, four, five.

Awesome.

Everything seems to be working correctly so far.

And let's use like a Channel Ten.

So one, two, three, four, five, six, seven, eight, nine, 10.

Awesome.

So that part this part of printing, all the values, all the natural numbers from one up to now seems

to be working correctly.

Now, what do we have to do is print all the values from num up to one, OK, right afterwards and how

should we basically do it?

So also again, there are a couple of options that we can use.

We can use a for loop, we can use a while loop.

There is no problem with using using either of them.

So I'm going to stick with the for loop.

So for I equals to num, that's the first value that I'm going to printing in this loop.

And as long as num I'm going to execute this loop, as long as, not as long as I is greater or equal

to one ok.

Or as long as I is greater than, than zero.

So and what operation are we going to do on each iteration.

So are we going still to go with like eight plus plus.

Probably not because we want to start from five for example, and then to go with for three to one up

until we reach these condition.

So it's probably going to be minus minus, which is basically in discriminating the value of I buy one

on every iteration.

So awesome.

And let's write the body of this loop.

So print F and the same, we will use percentage D again.

Just I.

OK.

So in these for a loop we will print from one to five in these four liberal print from five to one hopefully

if everything works.

Correctly.

And also, let's build and run it and see what happens.

So build and run my computer getting tired today.

What's going on?

So answer no, let's say five.

OK, so here you can see on the screen, one, two, three, four, five and five, four, three, two,

one.

Basically, everything seems to be working correctly.

The only thing that we should add is just to you know, we should separate between the lines.

So on the first line, we should point from one to five and on the next line we should print from five

to one.

So for that, we will simply add and print half of backslash and at the end of each of these four bluebook.

And it's kind of interesting question, why didn't we add a backslash and right here, so simple solution,

would it be that you don't want to print all the values one after another in use here?

I don't know a lot of rows, because if we would have used it this way, that in this case, it will

mean that on every iteration we will use a new line and we will not print one, two, three, four or

five on just one line.

But rather we would print one new line to new line three, new line four and so on.

So we only want to print a new line after we are done printing all the values from one to number and

also the same just for simplicity we will add after the second four for Loop.

And yeah, I think we are good.

We've done a pretty good job.

Let's just check it out if it works exactly as we expected.

Simply let's remove these for a loop.

OK, so let's remove it.

Let's remove the for loop and what we will say and let's make it as an example.

Let's create a temp variable just to store the value of a copy of the value.

So we'll say while no, there is no reason for using temp just here, so we will say I equals to one

initialize it and we will say as long as I use less than or equal to.

And in this case, we will print.

OK, so we initialize I and given we give it some value, some initialize value I equals to one.

As long as I is less than num we will print time.

So let's just make sure that it basically prints the one of the same solution as previously.

So enter num seven.

Oh we got a problem.

So what's the problem guys.

Take a second.

Think about it.

Why do we have an endless loop here.

So the answer is very simple because we print I as long as I's list the num ok and if nomy seven and

I's one then the slope is going to be infinite because I is not incremented by any number.

So what you can do about it is simply use plus plus.

OK, and that's on every duration I is going to be implemented by one and basically that's how you avoid

these endless loop.

So let's check it out once again, build and run it and let's see what's going on to be executed now.

Six, seven.

So one, two, three, four, five, six, seven, seven, six, five, four, three, two, one.

And there you go.

So basically, once again, we used a while loop in the for a loop.

And I've shown you you've you've seen how you can use it either while loop or for a loop, whatever

you like, whatever you prefer in this option.

Of course this I can be.

These I can be.

Where is it.

Lisa, I can be also removed and you can just use it in one line so it will print the value of it and

right afterward it will increment the variable.

I buy one after printing results just to show you that you will be 100 percent sure.

That is exactly how it works.

There you go.

The same results and yeah, feel free to use whatever you like.

The while loop for a loop.

And basically this is it for these video guys.

My name is Vlad Vlad Netsky actually.

And yeah.

And this is Alphatech Academy and feel free to ask any questions and of course leave some feedback,

some review so that this way I will know if you like the material so far or not.

And until next time, have a great day and I'll see you then.

Bye.

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