Hello and welcome to this video.
In this video I'm going to introduce you to four loops.
What is a for loop for loop is a type of loop that is used to iterate over a sequence so it will go
through a sequence of items of values.
This sequence is usually things like a list a tuple a dictionary is set or a string.
So he has to be a collection that the for loop can loop or iterate through.
The loop does not require an indexing variable in order to get initiated.
Just like with a while loop with a while loop in need to have an initial indexing variable for it to
work with.
You don't need that with a for loop.
Also a for loop can use a break and a continue statement so you can use two statements with a for loop.
So let me show you how a for loop works.
I'm going to create a variable which is going to be a list A list is basically a collection of items
of values.
So I'm gonna create a variable and we'll call it fruits.
And I'm going to set that to a course to a list.
And inside that list I'm going to add some items.
First item is going to be grapes I'm going to add a couple more.
Next I'm going to add berries and I'll do one more.
And finally I'm going to add oranges so I have now created my list.
So now I need to use a for loop to loop through the items in the loop in the list and print them out
in my console.
So to do that you need the four key word type you for.
And I'm going to just use a random ETA.
So I'm gonna say x so x basically is going to represent each item or each value in the list.
I'm gonna say for x in the variable called fruits want to add my colon and tab and I'm going to tell
it to print x.
And what does count do is going to print each item in my list on the screen.
So let me press the play button so you can see the output.
Click play and you can see here in the list you can see it has printed the items I've got grapes I've
got berries I've got oranges so you got grapes berries and oranges.
So that's what a for loop does it iterate over a collection of item or a list and then it does what
you tell it to do online.
For here I've told you to print the item so x here represent each of the items in the list.
So that's how for loop works.
Thanks for watching.
Bye for now.