Welcome back.
And this video we are going to check out for loops and they are used to iterate through rangers' arrays,
collections or anything that provides an iterator.
And you will learn about iterates arrays, ranges and collections in the future lectures.
So no worries there.
But basically, it's just a set of values that are stored in one construct or in one type of data type.
All right, as we've seen, there are multiple different data types such as and double strings and so
forth.
But there are also data types which can store many values at once and their types of collections or
raters.
All right, so what we can do is create four loops as well in codling and a for loop is also very similar
to a wire loop, so we can just go ahead and use to four key words and then number in one dot dot 10
and execute some code.
And I'm just going to execute actually got executed in one line.
Just going to say print number in a string.
All right.
So this for loop here, which we have in three lines, so to see is the same thing as our wire loop
that we had here where we needed to create a variable.
Then we had the condition, then we did the execution of something or write something on the screen,
and then we needed to take care of the condition at one point not being met anymore.
And that's it.
All right.
But now we sum everything up, so it's a lot shorter.
So here it just says for the number which is in this range of one to 10, please execute the code in
the block.
And in our case, we just do something simple where we just say, OK, print the number that you're
currently looking at.
So if we run this, we can see that it just prints one, two, three four and so forth up to the point
where it's 10.
So what a values tent.
All right.
So this is just one way of writing a follow up.
There are other ways as well.
You can also instead of saying them in so and so you can say I in one until 10.
So that will pretty much give us the same result where we, for example, just print I and I'm going
to add an empty space here.
Let's run this.
And we can see that printed the one two, three, four, four and so forth from before from this for
loop.
And then we have this one empty space to empty space and so forth from this forward.
So here we just use this until key word.
What would you say?
I want to have I in a range.
So this here is a range where what says start at one and go up until 10, now it goes the other way
around as well.
You've seen the key words down to so please.
Now go ahead and try to build a for loop, which goes from 10 down to one.
OK.
I hope you tried it because we just used this keyword already, so I thought it would be a great idea
to use it in here is a little challenge.
So for I in 10, down to one.
All right.
And I'm just going to say that there should be a line in between so that we see that this is tied down
to approach here that we had.
And there we are ten, nine, eight and so forth.
So what can you do if you want to have steps of not one, but let's say steps of two?
Well, you can simply add the key word step in here and then say how big the steps should be.
So down to one with the steps of two who run this, then we will see 10, eight, six four two and nothing
else.
That's it.
So there is another way of writing this what we have here.
So this down to approach and in general, four to four loops.
So this is pretty much the same as doing the following as if we had this line here start.
Step two.
OK.
So either you write the form of like this or you can also write the follow up like that where we just
used a slightly different approach.
All right.
But you can, of course, do the same thing for our other four loops up there as well.
So for the second one where we said I in one until 10, we can also say four I in one dot until 10.
Internally, the same thing will happen already.
So these are some examples for for loops.
We're going to use them extensively, especially as soon as we have collections, lists, arrays and
all those kind of cool type of collections.
So see you in the next video.