1 00:00:00,150 --> 00:00:02,780 Hello and welcome to this video. 2 00:00:02,820 --> 00:00:08,660 In this video I'm going to introduce you to four loops. 3 00:00:08,670 --> 00:00:18,450 What is a for loop for loop is a type of loop that is used to iterate over a sequence so it will go 4 00:00:18,570 --> 00:00:23,500 through a sequence of items of values. 5 00:00:23,580 --> 00:00:31,790 This sequence is usually things like a list a tuple a dictionary is set or a string. 6 00:00:31,800 --> 00:00:38,230 So he has to be a collection that the for loop can loop or iterate through. 7 00:00:38,490 --> 00:00:44,840 The loop does not require an indexing variable in order to get initiated. 8 00:00:44,850 --> 00:00:52,200 Just like with a while loop with a while loop in need to have an initial indexing variable for it to 9 00:00:52,200 --> 00:00:52,980 work with. 10 00:00:53,130 --> 00:00:55,620 You don't need that with a for loop. 11 00:00:55,620 --> 00:01:07,560 Also a for loop can use a break and a continue statement so you can use two statements with a for loop. 12 00:01:07,860 --> 00:01:10,980 So let me show you how a for loop works. 13 00:01:10,980 --> 00:01:18,600 I'm going to create a variable which is going to be a list A list is basically a collection of items 14 00:01:18,720 --> 00:01:19,500 of values. 15 00:01:19,920 --> 00:01:23,490 So I'm gonna create a variable and we'll call it fruits. 16 00:01:23,630 --> 00:01:27,630 And I'm going to set that to a course to a list. 17 00:01:27,900 --> 00:01:32,610 And inside that list I'm going to add some items. 18 00:01:32,610 --> 00:01:40,030 First item is going to be grapes I'm going to add a couple more. 19 00:01:40,030 --> 00:01:46,410 Next I'm going to add berries and I'll do one more. 20 00:01:46,750 --> 00:01:55,920 And finally I'm going to add oranges so I have now created my list. 21 00:01:55,970 --> 00:02:05,270 So now I need to use a for loop to loop through the items in the loop in the list and print them out 22 00:02:05,630 --> 00:02:07,040 in my console. 23 00:02:07,760 --> 00:02:13,070 So to do that you need the four key word type you for. 24 00:02:13,490 --> 00:02:17,680 And I'm going to just use a random ETA. 25 00:02:17,810 --> 00:02:25,190 So I'm gonna say x so x basically is going to represent each item or each value in the list. 26 00:02:25,250 --> 00:02:37,140 I'm gonna say for x in the variable called fruits want to add my colon and tab and I'm going to tell 27 00:02:37,140 --> 00:02:39,550 it to print x. 28 00:02:39,680 --> 00:02:48,360 And what does count do is going to print each item in my list on the screen. 29 00:02:48,750 --> 00:02:53,270 So let me press the play button so you can see the output. 30 00:02:53,340 --> 00:03:03,960 Click play and you can see here in the list you can see it has printed the items I've got grapes I've 31 00:03:03,960 --> 00:03:07,770 got berries I've got oranges so you got grapes berries and oranges. 32 00:03:07,770 --> 00:03:15,090 So that's what a for loop does it iterate over a collection of item or a list and then it does what 33 00:03:15,090 --> 00:03:16,480 you tell it to do online. 34 00:03:16,500 --> 00:03:25,890 For here I've told you to print the item so x here represent each of the items in the list. 35 00:03:26,010 --> 00:03:29,220 So that's how for loop works. 36 00:03:29,220 --> 00:03:30,600 Thanks for watching. 37 00:03:30,600 --> 00:03:31,330 Bye for now.