1 00:00:00,360 --> 00:00:02,640 Biton iterations using four. 2 00:00:04,140 --> 00:00:10,890 So the for loops index in Biton, the for loop in Python is used to iterate over a sequence, a sequence, 3 00:00:10,890 --> 00:00:16,970 maybe at least maybe a couple, maybe a string or any other iterable objects. 4 00:00:17,460 --> 00:00:20,730 So iterating over the sequence is also known as a traversal. 5 00:00:20,760 --> 00:00:22,170 That was for each and every looping. 6 00:00:22,170 --> 00:00:26,530 It will pick up one element from the iterator and that element can be processed. 7 00:00:26,820 --> 00:00:29,490 So here is that aspect of syntax for for. 8 00:00:29,820 --> 00:00:34,700 So for Val in sequence, don't forget to give this colon here. 9 00:00:34,830 --> 00:00:38,760 And if we get this colon, then automatically the next in line will have some indented. 10 00:00:39,060 --> 00:00:43,980 So body of what you can have the multiple statements you can write, but with the same indentation in 11 00:00:43,980 --> 00:00:44,470 that case. 12 00:00:45,360 --> 00:00:47,120 So here is a flowchart. 13 00:00:47,280 --> 00:00:54,450 So for each item in sequence, last item list, if it is not, the body of four will get executed on 14 00:00:54,450 --> 00:00:59,290 that item, which has been picked up in the last item has been missed, then it will exit loop. 15 00:00:59,430 --> 00:01:05,220 So in this way, the respective flowchart will be working on this for loop syntax in Python. 16 00:01:05,400 --> 00:01:12,390 We can also do this one using that range function so we can generate a sequence of numbers using range 17 00:01:12,390 --> 00:01:12,790 function. 18 00:01:12,830 --> 00:01:19,770 So for Loop can be operating on a certain sequence that is the eight objects and also using this range 19 00:01:19,770 --> 00:01:24,830 function to range, then will generate numbers from July to nine. 20 00:01:25,050 --> 00:01:27,220 So that is the ten numbers we are having here. 21 00:01:27,480 --> 00:01:30,840 So already Bimba here, Distin will not be inclusive. 22 00:01:31,050 --> 00:01:38,860 So 029 that the ten numbers we're having so we can also define the start, stop and Stepaside as range. 23 00:01:38,880 --> 00:01:42,000 This is a start, comma, stop, comma, step side. 24 00:01:42,180 --> 00:01:43,650 So this is Dipset. 25 00:01:43,830 --> 00:01:48,420 Defaults is one if it is not provided if you like. 26 00:01:48,420 --> 00:01:52,500 This one has range one comma ten comma one. 27 00:01:52,800 --> 00:01:59,160 That means it'll, it'll have the values ranging from one to nine and with the increment of one in that 28 00:01:59,160 --> 00:02:01,980 case for loop with the ls s.. 29 00:02:02,310 --> 00:02:06,630 So four for loop can also have an optional else block. 30 00:02:06,990 --> 00:02:13,440 The eighth part is executed when the items in the sequence used in for loop exhausts. 31 00:02:13,450 --> 00:02:18,470 So in that when the when the sequence will get exhausted then the else part will get over the control. 32 00:02:18,870 --> 00:02:21,900 So break stickman can be used to stop a for loop. 33 00:02:21,900 --> 00:02:25,880 In such case that else part will be ignored on the other end. 34 00:02:26,220 --> 00:02:30,550 So hence a for loops else part runs if no break occurs. 35 00:02:30,570 --> 00:02:33,600 So if there is a break then the spot will not be executed. 36 00:02:34,200 --> 00:02:39,370 Israel's part will be executed when the spot will be executed, when the sequence will get exhausted. 37 00:02:39,600 --> 00:02:45,660 So let us go for some practical demonstration to show you that how this force can be used in Python 38 00:02:45,660 --> 00:02:45,920 code. 39 00:02:46,260 --> 00:02:49,560 Let us find that how far Loop can work and Python. 40 00:02:50,130 --> 00:02:51,540 So here you have to find one. 41 00:02:51,540 --> 00:02:57,510 At least we know that list elements are to be separated by commas and they are to be enclosed within 42 00:02:57,510 --> 00:02:58,830 this code brackets. 43 00:02:59,190 --> 00:03:01,190 So this is our list here. 44 00:03:01,560 --> 00:03:07,950 So printing all elements present in a set and had this particular set is nothing, but at least so for 45 00:03:07,950 --> 00:03:16,440 I in a print that in each and every iteration, in each and every loop in this particular form using 46 00:03:16,440 --> 00:03:22,440 this for we are picking up one element from that list at the time and the respective element is going 47 00:03:22,440 --> 00:03:23,080 to get printed. 48 00:03:23,100 --> 00:03:25,160 So here is the outcome for this code. 49 00:03:25,500 --> 00:03:29,970 So the first iteration, it is picking up one, then two, then three at that atlas. 50 00:03:29,970 --> 00:03:32,820 It is picking a fight so that lists all this list. 51 00:03:32,820 --> 00:03:40,650 Members are to be picked up to be to be read from the list in the order in which they are appearing 52 00:03:40,650 --> 00:03:41,280 in the list. 53 00:03:41,730 --> 00:03:42,810 So that is our fault. 54 00:03:43,290 --> 00:03:51,020 So for I in so this is a syntax syntax, the grammar to write this for, so for I in a then colon so 55 00:03:51,030 --> 00:03:54,210 colonially indicate that next step will be under this body. 56 00:03:54,630 --> 00:03:58,230 So you can find that if you write here print say hello. 57 00:03:59,520 --> 00:04:04,760 That is also coming within this form so we can find that it is printing like this. 58 00:04:05,190 --> 00:04:08,850 So I want to bring this one and hello side by side so we can go for this. 59 00:04:10,220 --> 00:04:14,300 It is not like this one and then you can print this, hello? 60 00:04:14,330 --> 00:04:15,410 So what will happen? 61 00:04:15,410 --> 00:04:18,150 This one and Halo will get printed in the same line. 62 00:04:18,630 --> 00:04:24,320 So in this way, you can write so many different statements with this indentation to indicate that all 63 00:04:24,320 --> 00:04:27,410 the statements are within the four block. 64 00:04:28,070 --> 00:04:29,530 Let us go for the next one here. 65 00:04:29,540 --> 00:04:30,470 We're using four. 66 00:04:30,470 --> 00:04:36,450 But using this range, we know that here we are given the range that is six Kharma 11, that was a value 67 00:04:36,560 --> 00:04:36,710 up. 68 00:04:36,710 --> 00:04:38,840 I would be ranging from six to 10. 69 00:04:38,850 --> 00:04:40,350 So let me go for the execution. 70 00:04:40,370 --> 00:04:46,460 You see the IIS being initialized with six to 10 for each and every time iteration after that so we 71 00:04:46,460 --> 00:04:51,800 can put some step peloso here to stabilize to that when the increment value is to here. 72 00:04:52,070 --> 00:04:58,130 So now it will go on picking up six, eight and 10 because 11 is not inclusive. 73 00:04:58,310 --> 00:05:01,870 And that's why it will print the values from six to 10. 74 00:05:02,120 --> 00:05:08,000 And with this increment factor of two in this way, you can write this for and using this range function 75 00:05:08,210 --> 00:05:09,150 in our volume. 76 00:05:09,770 --> 00:05:11,760 So let us go for another another way. 77 00:05:11,780 --> 00:05:13,180 So how to write this one? 78 00:05:13,190 --> 00:05:20,660 You can find that it wasn't for loop for printing the values present in the table and using the Ellspermann 79 00:05:20,660 --> 00:05:21,710 in the for loop. 80 00:05:21,720 --> 00:05:23,770 So how to do that one you can print sick. 81 00:05:24,800 --> 00:05:31,820 So this outcome we're having so basically to 11, 12, 13, 14 and 15, so they are coming here and 82 00:05:31,820 --> 00:05:34,280 this is nothing but a double for I. 83 00:05:34,280 --> 00:05:40,450 Inbee So it would be picking up the values from this one value at a time in each and every iteration. 84 00:05:40,790 --> 00:05:47,300 And when this particular you get exhausted, the else block will get to control and then printing completed, 85 00:05:47,300 --> 00:05:49,590 that message is going to get printed. 86 00:05:50,090 --> 00:05:53,410 So there is another way to write a for loop in our python coding. 87 00:05:53,930 --> 00:06:00,680 So in this demonstration, we have shown you that how to write for in Python code to have some block 88 00:06:00,680 --> 00:06:04,490 to get executed repeatedly for multiple number of times. 89 00:06:05,180 --> 00:06:06,380 Thanks for watching this video.