We will now see how a for loop is actually implemented in Python so whenever we want to iterate over
an AI trouble using a for loop.
This is the statement used for AI which represents the AI terrible key in the AI terrible using the
statement.
The for loop automatically items over the elements in the list since we have we are using a for loop.
We don't need to call the next method and also we don't have to worry about these top ideation.
Exception being raised we will now take a closer look at how the for loop is actually implemented in
Python.
So when you give this statement in your program define lube internally.
Create an item later object that does by passing the item again do the ITER function and I directed
object is generated.
Next after generating an eye iterator object the for loop secretly calls the next function on this later.
Object
and the next function hold the logic to compute the next item in the sequence which is then handed back
to the for loop.
So the for loop uses an infinite while loop to iterate over the items in the sequence and using the
next function it is going to compute the values in the sequence.
If the next function reaches the end of the sequence end of the item later object then we are going
to catch the stop ie duration exception but for a for loop we are not going to throw any error the Far
Low gracefully handles and conceals this exception.
So that is the reason we have a break statement here.
Once the next function does not have any values to compute in the AI director object we are going to
break out of the Y Lu.
So during each iteration the for loop secretly calls the next function and the ITER data remembers its
date and rather than yielding the first item it resumes where it left off.
So we have just discussed how the for loop is implemented in Python.
We will now see how this actually works in the Jupiter notebook.
So we have a list.
We will now use the ITER function in order to convert this list when I directed object which is done
by the for loop internally behind the scenes.
So let's call this AI iterator ITER for outdated object.
And this is generated by passing the identical list one to the ITER function object ITER for is a list
either A2 after generating the data object the for loop secretly cause the next function and it ITER
toward the values in the sequence using an infinite while loop.
So during each cycle of an ideation the for loop secretly calls the next function.
Again so we are going to call the next function on the ITER data object not to generate this variable
item then you're going to print this item once it encounters these top ideation exception.
We're going to break out of the loop so let's execute this piece of code.
So when we execute this piece of code the items in the eye trouble are either rated and then displayed
in the output using a for loop.
The citation is performed automatically on an eye trouble.
If you want to manually ITER it or the elements in the nitrogen we can use these ITER and the next functions.