1 00:00:00,420 --> 00:00:02,640 By Tony Traditions using for. 2 00:00:04,200 --> 00:00:10,890 So the for loops indexing Biton the for Lupin Python is used to edit it over a sequence and sequence, 3 00:00:10,890 --> 00:00:17,010 maybe at least maybe a double, maybe a string or any other iterable objects. 4 00:00:17,520 --> 00:00:20,570 So iterating over the sequence is also known as a diverse. 5 00:00:20,730 --> 00:00:26,550 That was for each and every looping it pick up one element from the editor and that element can be processed. 6 00:00:26,880 --> 00:00:29,450 So here is a despicable syntax for four. 7 00:00:29,880 --> 00:00:31,860 So for Val in sequence. 8 00:00:32,100 --> 00:00:34,560 Don't forget to give this colon here. 9 00:00:34,900 --> 00:00:38,760 And if you get this colon, then automatically the next line will have some indented. 10 00:00:39,090 --> 00:00:40,100 So body of thought. 11 00:00:40,380 --> 00:00:41,730 You can have the multiple statements. 12 00:00:41,730 --> 00:00:42,250 You can write. 13 00:00:42,420 --> 00:00:44,520 But with the same indentation in that case. 14 00:00:45,390 --> 00:00:47,100 So here is a flowchart. 15 00:00:47,340 --> 00:00:49,410 So for each item in sequence. 16 00:00:49,590 --> 00:00:50,730 Last item list. 17 00:00:51,480 --> 00:00:57,030 If we just know the body of four will get executed on that item, which has been picked up in the last 18 00:00:57,030 --> 00:00:57,950 item has been missed. 19 00:00:58,080 --> 00:00:59,310 Then it will exit loop. 20 00:00:59,490 --> 00:01:05,080 So in this way, the respective flowchart will be working on this for loop syntax in by time. 21 00:01:05,430 --> 00:01:12,390 We can also do this one using that range function so we can generate a sequence of numbers using range 22 00:01:12,390 --> 00:01:12,800 functions. 23 00:01:12,840 --> 00:01:16,620 So far, Loop can be operating on a certain sequence. 24 00:01:16,770 --> 00:01:21,150 That is, the editable objects are also using this range function to range. 25 00:01:21,190 --> 00:01:24,870 Then will generate numbers from G2 to nine. 26 00:01:25,110 --> 00:01:27,210 So that is the ten numbers we are having here. 27 00:01:27,510 --> 00:01:30,820 So always remember here, this 10 will not be inclusive. 28 00:01:31,080 --> 00:01:31,800 So zero to nine. 29 00:01:31,920 --> 00:01:33,240 That is a ten numbers we are having. 30 00:01:33,600 --> 00:01:38,690 So we can also define the start, stop and step side as range. 31 00:01:38,910 --> 00:01:39,690 This is a start. 32 00:01:39,690 --> 00:01:40,140 Comma. 33 00:01:40,350 --> 00:01:40,770 Stop. 34 00:01:40,770 --> 00:01:41,250 Comma. 35 00:01:41,400 --> 00:01:42,050 Step side. 36 00:01:42,240 --> 00:01:45,150 So SIST Estep site defrauds is one. 37 00:01:45,330 --> 00:01:49,860 If it does not provide it, let us know if we like this one has range. 38 00:01:50,010 --> 00:01:52,530 One comma ten comma one. 39 00:01:52,860 --> 00:01:56,730 That means it'll, it'll have the values ranging from one to nine. 40 00:01:57,380 --> 00:02:02,010 And with the increment of one in that gets for loop with the else section. 41 00:02:02,370 --> 00:02:05,640 So ForFour Loop can also have an optional. 42 00:02:05,730 --> 00:02:08,640 Else block the eighth spot is executed. 43 00:02:08,700 --> 00:02:13,350 When the items in the sequence used in for loop exhausts. 44 00:02:13,500 --> 00:02:18,450 So in that when the when the sequence will get exhausted then the else part will get over the control. 45 00:02:18,900 --> 00:02:21,810 So break stickman can be used to stop a for loop. 46 00:02:21,990 --> 00:02:24,850 In such case the ill spot will be ignored. 47 00:02:25,170 --> 00:02:25,860 On the other end. 48 00:02:26,250 --> 00:02:28,750 So here's a for loops ILS part runs. 49 00:02:29,010 --> 00:02:30,450 If no break occurs. 50 00:02:30,630 --> 00:02:31,740 So if there is a break. 51 00:02:31,890 --> 00:02:33,570 Then the L spot will not be executed. 52 00:02:33,950 --> 00:02:37,190 Others it's partly because the Goodhead Lindale spot will be excluded. 53 00:02:37,410 --> 00:02:39,390 When the sequence will get exhausted. 54 00:02:39,630 --> 00:02:45,630 So let us go for some practical demonstration to show you that how this fault can be used in Python 55 00:02:45,630 --> 00:02:45,890 code. 56 00:02:46,320 --> 00:02:47,240 Let us find that. 57 00:02:47,270 --> 00:02:49,470 How far Loop can work in Python? 58 00:02:50,190 --> 00:02:51,740 So here to define what list. 59 00:02:52,100 --> 00:02:58,350 We know that list elements are to be separated by commas and they are to be enclose within this card 60 00:02:58,350 --> 00:02:58,820 brackets. 61 00:02:59,220 --> 00:03:01,170 So this is our list here. 62 00:03:01,620 --> 00:03:04,330 So printing all elements present in a set. 63 00:03:04,480 --> 00:03:06,150 Had had this particular set is lacking. 64 00:03:06,210 --> 00:03:09,980 But at least so far, I in a print I. 65 00:03:10,030 --> 00:03:14,000 That this in each in a precondition in each and every loop. 66 00:03:14,840 --> 00:03:21,570 This particular for using this for we are picking up one element from that list at a time and the respective 67 00:03:21,630 --> 00:03:23,070 element is going to get better. 68 00:03:23,130 --> 00:03:25,120 So here is the outcome for this code. 69 00:03:25,560 --> 00:03:29,910 So the first iteration, it is picking up one, two and three at that address. 70 00:03:29,930 --> 00:03:37,170 It is picking a fight so that this all guest list members are to be picked up to be to be read from 71 00:03:37,170 --> 00:03:41,280 the list and the order in which they are appearing in the list. 72 00:03:41,790 --> 00:03:42,790 So take this over forward. 73 00:03:43,350 --> 00:03:44,670 So far I in. 74 00:03:44,700 --> 00:03:45,870 So this is a syntax. 75 00:03:46,170 --> 00:03:47,400 Syntax means that grammar. 76 00:03:47,520 --> 00:03:48,390 Right this far. 77 00:03:48,630 --> 00:03:50,700 So for I in a column. 78 00:03:50,820 --> 00:03:54,210 So indicate that next step may be under this body. 79 00:03:54,660 --> 00:03:56,220 So you can't find that if we write here. 80 00:03:56,250 --> 00:03:56,710 Print. 81 00:03:57,660 --> 00:03:58,200 Say hello. 82 00:03:59,510 --> 00:04:01,240 That is also coming. 83 00:04:01,490 --> 00:04:04,770 We didn't this far, so we can find that it is printing like this. 84 00:04:05,250 --> 00:04:06,710 So I want to bring this one in. 85 00:04:06,720 --> 00:04:07,690 Hello, Side-By-Side. 86 00:04:07,740 --> 00:04:08,880 So we can go for this. 87 00:04:10,310 --> 00:04:11,740 It is legal to now. 88 00:04:11,960 --> 00:04:13,990 You can write this one and then you can print this. 89 00:04:14,000 --> 00:04:14,250 Hello. 90 00:04:14,330 --> 00:04:15,380 So what will happen? 91 00:04:15,410 --> 00:04:18,080 This one and Unhallowed will get printed in the Cymbeline. 92 00:04:18,520 --> 00:04:23,750 So you can in this way, you can write so many different statements with this indentation to indicate 93 00:04:23,750 --> 00:04:27,410 that all the statements are within the four block. 94 00:04:28,150 --> 00:04:30,450 Let's go for the next one here to using forward. 95 00:04:30,470 --> 00:04:35,240 But using this range, we know that here too are given the range that is six comma element. 96 00:04:35,270 --> 00:04:36,700 That was a value up. 97 00:04:36,720 --> 00:04:38,810 I would be ranging from six to 10. 98 00:04:38,900 --> 00:04:40,310 So let's go for the execution. 99 00:04:40,400 --> 00:04:45,150 You see, the eye is being initialized with six to 10 for each and every time iteration. 100 00:04:45,680 --> 00:04:48,100 After that, you also you can put some step Peluso here. 101 00:04:48,150 --> 00:04:49,170 This table is two. 102 00:04:49,190 --> 00:04:51,800 That means the increment value is two here. 103 00:04:52,130 --> 00:04:58,050 So now we do go on picking up six, eight and 10 because Aylwin is not inclusive. 104 00:04:58,430 --> 00:05:01,860 And that's why it will print the values from six to 10. 105 00:05:02,240 --> 00:05:08,000 And with this increment factor of two in this way, you can write this for and using this range function 106 00:05:08,300 --> 00:05:08,930 in our four. 107 00:05:09,800 --> 00:05:11,750 So let us go forward and adapt another way. 108 00:05:11,780 --> 00:05:13,130 So how to write this one? 109 00:05:13,220 --> 00:05:20,140 You can find that using for love, for printing the values present in the couple and using the elf. 110 00:05:20,150 --> 00:05:21,680 Come on in the follow up. 111 00:05:21,740 --> 00:05:23,760 So how do you do that when you confront sic? 112 00:05:24,860 --> 00:05:30,170 So this outcome we're having so Beezy, go to eleven, twelve, thirteen, fourteen and fifteen. 113 00:05:30,200 --> 00:05:31,260 So they are coming in. 114 00:05:31,610 --> 00:05:38,480 And this is nothing but a double for I in B C to be picking up the Velas from this double one value 115 00:05:38,510 --> 00:05:40,430 at the time in each and every condition. 116 00:05:40,880 --> 00:05:46,670 And when this particular couple we get exhausted then else Blokland get the control and then printing 117 00:05:46,670 --> 00:05:47,270 completed. 118 00:05:47,300 --> 00:05:48,490 That message is good. 119 00:05:48,530 --> 00:05:49,610 Went to get printed. 120 00:05:50,120 --> 00:05:53,370 So there is another way to write the for loop in our python coding. 121 00:05:53,960 --> 00:06:00,650 So in this demonstration we have shown you that how to write fault in our python code to have some block 122 00:06:00,680 --> 00:06:04,520 to get executed repeatedly for multiple number of times. 123 00:06:05,210 --> 00:06:06,340 Thanks for watching this video.