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
What is going on, guys?
My name is Vlad.
And in this video, we are going to take a look at for loops in C programming language at this point.
We understand the concept and the main principles of for loops as we've discussed it in the previous
video.
And now it's time for some Hands-On.
So supposedly you have to write a program that reads a number from the user and then prints all the
numbers from one to you.
That particular number.
So first of all, we just create declaring non variable.
Then we read it from the user and through a number.
And based on the number of that the user inserts, we are going to print all the numbers, all the numbers
from one to these particular numbers.
So while if, for example, he entries in NUM equals to five, we are going to print one, two, three,
four, five.
Is that clear?
And if the user inserts ten, then we are going to print all the numbers from one to ten and so on.
Basically you got the idea.
So one of the ways to do so would be by using the four loops.
So basically the structure would be something like that.
So first of all, you specify the four statement.
You use the four.
And then you are going to have the parentheses to hold the three states or condition was specified in
the previous video.
So first of all, we are going to have the initialization phase phase and initialization phase, which
basically you specify that I will be equal to one.
And you only run this command only for the first time that you happen to see these for a loop.
So there you go.
For example, you print this line for the screen, then you read the value from the user.
And the first time that you come to this fourth statement to the force structure, only now you're going
to set this value to be equal to one and then you move on to the loop condition.
And in this condition, you actually check whether AI is less than or equal to NARM.
And if the result of the condition happens to be true or better as say, as long as this condition happens
to be true, you are going to execute the loop body.
So on every duration, once again, on every duration that you are going to execute the slope, you're
going to check if this condition is satisfied.
If it's satisfied.
If it's true, you are going to execute.
If it's false, you are going to be kicked out.
Let's say this way to be kicked out.
Out of this for a loop end to proceed on with your program.
So let's say that you've, Ryan, of these for the first time, you've ran the first iteration, you
checked out.
This condition happens to be true.
One is less than five.
Let's say that name is five.
So you printed out one to the screen, right?
Because the value of AI is just one.
You printed out one to the screen on the first iteration.
Then you come to the end of this loop body.
And what happens now?
Now, what happens is these Abdeen statement is being executed, meaning that AI is getting increased
by one.
Right.
And from this point on, before we start the second iteration, I will be equal to two.
So this happens after any duration is over.
And we print it out on the screen.
Then we incremented.
We updated this statement.
We incremented I by one.
And then to enter the loop body to run the loop body once again.
We check out if this condition is true or false.
And in this case, two is less than or equals two to five.
Right.
This condition is true.
Then we are going to execute the loop body once again.
All right.
So this is the new body we are going to executed once again.
And we are going to print to to the screen.
So also, we do it the same way for the 30 duration.
We increment I by one.
I will be equal to three.
Three is less than five.
We're going to print three to the screen.
And so on until we reach some condition that I will be or it will be greater than five.
Right.
If it's five, five is less than or equal to NARM.
So five will will be printed.
And we will see all the numbers from one till four to five on the screen.
And then we run this print f commented once again we increment I by one end.
And now I will be equal to six.
And six is not less than or equals to five than the result of this condition will be false.
And that means that you are not going to execute this loop body and you're going to step out of the
for a loop.
And just to proceed with your programming in this case, just return zero and get it over with.
All right.
So I hope you've got the point.
And just to make sure that you understand all the flow of of this code correctly, let's see another
example where we go step by step in the most detailed explanation, because a lot of student.
Are struggling at this point, and I don't want you guys to be one of these students that struggle at
for loops.
So here we come for the first time, we come from this line.
And what we are doing is we set of the value of I to be equal to one than we are.
All right.
We have here the variable I we set it to be equal to one and then we are moving on the little body.
So the first command that will be executed is the printf command.
And we can see, let's say that this is the screen of your computer.
This is the console application.
We are going to see that one has been printed out to the screen.
And now we come back to the end of the look of the loop, buddy.
And what we should do from now on.
From now on, we should move here and increment I by one.
So now the variable I we created a variable I in the first steps of our program, this variable will
be incremented by one.
So I will be equal to two.
From this point on before we start the second the duration.
So now we are going to come here only only if this condition is satisfied.
And to do we can see that I equals to two.
That two is less than five.
Nahm in our case was five.
So now we are going to run this command once again.
So print f the value of I.
And now the value of Feis to us.
So we are going to print to, to the screen.
And now we are going to repeat this process.
So we are going to increment I by one and I'm going to be equal to three.
Then we come again for the loop body based on the result of this condition.
We checked it on.
The result is true.
So now we execute this line one once again.
And we can see that all the numbers will be printed as a screen.
My bet.
The user didn't enter a name equals to five, but rather he entered nom equals to ten.
I forgot exactly what he enters.
Right.
It's late hours right now.
So please forgive me, guys.
And I basically hope that you got the idea of how this code works and you just run this little body
over and over again until this condition.
Feel this condition is will be false.
And while it's not false, let's say.
And on the end of every duration you use of this command to increment I by one in this example.
It's it's just by one.
It may be in other value.
It may be another command, whatever you you choose.
And also just remember that this line, that this command is executed just once when you come for the
first loop for the first time.
All right.
So now let's take look at another example where we have to print just odd numbers.
All right.
From one app to a given number that the user provides.
It's pretty similar to what we've done in the previous example.
But there just now, we are going to print all the numbers from one of the old numbers sorry, all the
old numbers from one field.
These given no.
So the steps are very similar.
First of all, we will create AI to be equal to one.
So there you go.
You, first of all, created AI.
All right.
This is this line we we presented with this box and then we use said this value to be equal to one.
And then we are going to execute the loop body and print one to the screen.
So one will be printed here.
Now we can see that the little buddy is over.
And what we should do now.
Should we increment just by one as previously?
And then we will print one, two, three, four or five, six, seven and so on.
But that's not exactly what we want to do.
We want to bring just the odd numbers.
So on every direct iteration, on the end of at the end of every iteration, we are going to increment
the value of AI by two.
So in this case, we run these command AI equals to the previous AI plus two.
So the value of AI becomes three.
And now once you come back to the Labadee, you're going to print three two discrete to the screen and
then you increment the value by or by two.
You are going to have here five and you're going to print five and so on.
So for us, simply printing out all the odd numbers from one to these given narm that the user specifies.
And that would be it for these video guys.
And I think and I hope you understand now much better how the four loops work and see how this syntax
looks like.
What are all these commands to what they relayed.
Which commands.
Ron.
Before the iteration.
After the iteration.
What is the condition that is checked.
If the loop body should be executed or not.
And we've seen full examples demonstrated line by line, command by command.
What commands are executed and when?
So I think you can say that, you know, for a loops.
And now I would say that it's time to give it a little bit of practice on your own.
So I'll see you in the next.
Challenge.
Good bye, guys.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.