1 00:00:00,420 --> 00:00:08,950 We will now see how a for loop is actually implemented in Python so whenever we want to iterate over 2 00:00:09,010 --> 00:00:11,440 an AI trouble using a for loop. 3 00:00:11,560 --> 00:00:21,570 This is the statement used for AI which represents the AI terrible key in the AI terrible using the 4 00:00:21,570 --> 00:00:22,660 statement. 5 00:00:22,820 --> 00:00:31,090 The for loop automatically items over the elements in the list since we have we are using a for loop. 6 00:00:31,160 --> 00:00:37,180 We don't need to call the next method and also we don't have to worry about these top ideation. 7 00:00:37,280 --> 00:00:46,830 Exception being raised we will now take a closer look at how the for loop is actually implemented in 8 00:00:46,830 --> 00:00:47,440 Python. 9 00:00:48,210 --> 00:00:55,170 So when you give this statement in your program define lube internally. 10 00:00:55,260 --> 00:01:03,660 Create an item later object that does by passing the item again do the ITER function and I directed 11 00:01:03,750 --> 00:01:06,440 object is generated. 12 00:01:06,750 --> 00:01:18,660 Next after generating an eye iterator object the for loop secretly calls the next function on this later. 13 00:01:18,720 --> 00:01:19,260 Object 14 00:01:22,640 --> 00:01:31,920 and the next function hold the logic to compute the next item in the sequence which is then handed back 15 00:01:31,920 --> 00:01:33,440 to the for loop. 16 00:01:33,960 --> 00:01:44,430 So the for loop uses an infinite while loop to iterate over the items in the sequence and using the 17 00:01:44,430 --> 00:01:49,030 next function it is going to compute the values in the sequence. 18 00:01:49,110 --> 00:01:57,210 If the next function reaches the end of the sequence end of the item later object then we are going 19 00:01:57,210 --> 00:02:09,180 to catch the stop ie duration exception but for a for loop we are not going to throw any error the Far 20 00:02:09,180 --> 00:02:14,440 Low gracefully handles and conceals this exception. 21 00:02:14,440 --> 00:02:18,170 So that is the reason we have a break statement here. 22 00:02:18,190 --> 00:02:25,780 Once the next function does not have any values to compute in the AI director object we are going to 23 00:02:25,780 --> 00:02:27,730 break out of the Y Lu. 24 00:02:27,820 --> 00:02:37,880 So during each iteration the for loop secretly calls the next function and the ITER data remembers its 25 00:02:37,890 --> 00:02:43,110 date and rather than yielding the first item it resumes where it left off. 26 00:02:43,680 --> 00:02:48,420 So we have just discussed how the for loop is implemented in Python. 27 00:02:48,480 --> 00:02:53,760 We will now see how this actually works in the Jupiter notebook. 28 00:02:53,850 --> 00:02:55,450 So we have a list. 29 00:02:55,800 --> 00:03:03,060 We will now use the ITER function in order to convert this list when I directed object which is done 30 00:03:03,060 --> 00:03:06,930 by the for loop internally behind the scenes. 31 00:03:06,960 --> 00:03:12,220 So let's call this AI iterator ITER for outdated object. 32 00:03:12,690 --> 00:03:21,630 And this is generated by passing the identical list one to the ITER function object ITER for is a list 33 00:03:21,770 --> 00:03:33,540 either A2 after generating the data object the for loop secretly cause the next function and it ITER 34 00:03:33,610 --> 00:03:39,700 toward the values in the sequence using an infinite while loop. 35 00:03:39,720 --> 00:03:48,550 So during each cycle of an ideation the for loop secretly calls the next function. 36 00:03:48,600 --> 00:03:57,160 Again so we are going to call the next function on the ITER data object not to generate this variable 37 00:03:57,610 --> 00:04:05,430 item then you're going to print this item once it encounters these top ideation exception. 38 00:04:05,420 --> 00:04:10,700 We're going to break out of the loop so let's execute this piece of code. 39 00:04:10,880 --> 00:04:19,860 So when we execute this piece of code the items in the eye trouble are either rated and then displayed 40 00:04:19,920 --> 00:04:23,250 in the output using a for loop. 41 00:04:23,280 --> 00:04:27,500 The citation is performed automatically on an eye trouble. 42 00:04:27,540 --> 00:04:35,280 If you want to manually ITER it or the elements in the nitrogen we can use these ITER and the next functions.