Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
OK, so welcome back to the Solution video, and hopefully you tried to solve this exercise by coming
up with at least one or two solutions for this problem, one solution that uses conditions and the other
solution that does not use condition.
So let's start with, first of all, reminding of what this exercise is all about and then continuing
with the first option, the first solution, discussing what is what are we going to use there, how
it's going to be implemented, and then move on to the second solution and also talk about probably
some bugs that you may get while using the second solution and how it may be also avoided.
So get yourself something nice to drink and let's start in.
The first thing that we are going to do is just to make some reminder.
So what we want to do is just to print no even numbers starting starting from the value of two.
OK, so we've seen one example that if we have nonliving equals to five, then in this case what we
will do is just print all the values from two.
Basically no time now.
Even values starting from two.
OK, two, four, six, eight, 10, a total of five or num values.
So awesome.
And with that being said, let's show them basically the preferrable solution.
Start with it.
And the solution includes using some loops.
Right.
Of course the first one and the second one probably will.
Both of them.
Both of them will include the usage of Loopt.
And in the first one we will use it for a loop.
So for a for a loop, let's create additional variable.
I and also, of course, let's create not just made the usual process of Antonoff and then reading the
value from the user and storing it inside the variable number cited variable noun.
Now that we are ready, we can move on to using the for loop.
So basically, what should be the for loop?
What should we what would you need all be able to for I equals to one as long as I use less than or
equal to none.
So that's what we are going to do.
And the question is, if this solution is OK, what do you think?
So printf percentage being just printing the value of it.
So take a second and think about it.
Do you think the solution is OK?
What will it print, for example, if we get I don't know here, if we get Nomikos to five, what will
be printed on the screen?
Basically the solution is very simple, right?
It will print all the values from one up to none, and that's it.
But that's not something that we want, right?
Because if we will build and run it, then we will see.
Yeah.
And we will see basically guys sorry for this transition and just needed to fix something in the code
blocks.
So once again, let's make a quick reminder.
We basically created these for a loop and we want to see how it works if we build and run it.
So build and run.
And we will be able to see in our console application that if we insert the value of five, then in
this case all the numbers from one up to five will be printed.
But that's not something that we want because we want to print all the even numbers starting from two.
And the main question that you should ask yourself, basically, how should you do it?
You can't simply print from starting from one and how you will need to print two, four or six and so
on, not Naameh times.
So there are basically even here using these for a loop.
There are a couple of options.
And the first option is simply to realize that if you have a sequence of numbers starting from one,
two, three, four, let's say we had five, then in this case it will simply simply print the value
of I multiplied by two.
We'll print the following sequence two, four, six, eight and 10.
Right.
So we will have like to understand that if we start from equals to one and we multiplied by two, we
simply start these four, all of these printing operations from two.
And we would do it.
How many times sometimes.
OK, so that's one option to solve this exercise.
So let's let's build and run it and let's go.
Let's go, let's go.
Come on.
OK, so now equals two five.
So there you go.
Two, four, six, eight and 10.
And that's also a good question.
A good question.
I'm saying a good solution to this exercise.
And another option that we can use is simply going like this.
So let's say that's the first option.
OK.
Option number one, OK.
And we will also put it in comment.
That's basically how you create a multi line comment.
And now let's go with option number two.
So option number two goes like this.
We simply didn't have any clue about these combination that we can multiply every value of I by two
and getting like the sequence that we want exactly like it was requested in the exercise.
So the second condition can go like this.
So for I equals to two, the second option, because we know that we should start printing from two
and we should do it as long as I use less than or equal to, to what that we you have to think about
it as long as want.
So that's one question.
What should we put here.
One option is maybe let's try using here as long as I is less than or equal to num multiplied by two.
Is this option OK?
Probably not.
So we can see that using the for a loop is also optional, but it will be kind of problematic right
now.
So one other option that we would use is a while loop.
So as long as none is greater than zero.
So in this case we will initialize EI of the beginning to be equal to two.
And then what we will do is just printing the value of I OK, the value of EI.
So first of all we will print two and then we need to increment or basically multiply the value of I
by two.
Right.
So it will be something like that.
I multiplied by two because if we multiplied two will get different numbers, but I plus equals to two.
So basically taking the previous value of EI and multiplying and adding to it the value of two.
So I equals to EI plus two.
OK, and also what we have to do, because what will be the problem, the solution, if we run these
wire loop and we build and run it, then in this case, what will happen is very simple.
Let me show you guys.
So if you do something like this, you enter five and then you press enter, then you will see all the
numbers and your program is probably going to get stuck.
So how to avoid it?
So we know that these wireless currently is an infinite loop and we want to avoid it.
So in this case, what we will need to do is simply to use numbers equals to the previous number, minus
one, because we want to do this operation just some times.
So that's basically how you can do it.
So build and run it.
And let's use the value of seven for this example.
So two, four, six, eight, 10, 12 and 14.
And there you go.
So to summarize the two options that I came across and showed you guys, of course, there are also
additional options that we may use using you for a loop and also the wire loop.
But that's basically the two most common options, the two most common solutions that my students tend
to use.
So that's why I brought you these solutions to this exercise.
So, yeah, take your time, guys.
Try to solve it on your own if you did not do it successfully.
And I wish you a great day and good luck with this exercise and with our following exercises.
My name is Vlad and I will see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.