1 00:00:00,000 --> 00:00:03,300 And before we continue, one thing to know is to 2 00:00:03,300 --> 00:00:07,500 know how to iterate on list with loops. So you 3 00:00:07,500 --> 00:00:11,310 can perform a set of instructions for each element 4 00:00:11,340 --> 00:00:13,950 on the list. And I'm going to show you this now, 5 00:00:13,950 --> 00:00:16,920 because simply, you're going to use this multiple 6 00:00:16,920 --> 00:00:19,950 times in every project you create in the future. 7 00:00:20,100 --> 00:00:22,410 Okay, so I'm not going to introduce any new 8 00:00:22,410 --> 00:00:24,990 concepts to you now. We are just going to use 9 00:00:25,020 --> 00:00:27,630 what we saw previously. And let's get started with 10 00:00:27,630 --> 00:00:30,750 an example. And I'm going simply to comment this, 11 00:00:30,750 --> 00:00:33,420 okay, so we don't use it, I can remove it, I could 12 00:00:33,420 --> 00:00:35,520 comment it, if you want to comment, you can go on 13 00:00:35,520 --> 00:00:38,250 Code, Comment with Line Comments here, and you 14 00:00:38,250 --> 00:00:41,700 have the shortcut if you want. Alright, so now the 15 00:00:41,700 --> 00:00:44,790 program basically has nothing in it. I'm going to 16 00:00:44,790 --> 00:00:52,374 create a number_list. Okay, let's see 3, 5, 8, 12, -3, 17 00:00:52,374 --> 00:00:56,790 -7. Okay. And then I'm going to do 18 00:00:56,790 --> 00:01:03,450 for number in number_list. And I'm going to print 19 00:01:04,110 --> 00:01:08,400 number. This is going to go through all the 20 00:01:08,430 --> 00:01:11,790 elements of the lists. And every time we enter the 21 00:01:11,880 --> 00:01:15,390 for loop, the number variable here will contain 22 00:01:15,420 --> 00:01:18,780 the next element on the list. And we can actually 23 00:01:18,780 --> 00:01:22,050 use that to do anything we want here. As you can 24 00:01:22,050 --> 00:01:24,900 see, that is quite similar with this, okay, we 25 00:01:24,900 --> 00:01:29,700 have for i in range(10), range(10) is actually a 26 00:01:29,700 --> 00:01:32,880 list between zero and nine. So we have the same 27 00:01:32,880 --> 00:01:37,560 thing here for, we just don't use i as an index. 28 00:01:37,620 --> 00:01:40,740 Okay, as a counter, we use a no meaningful name 29 00:01:40,740 --> 00:01:44,130 here because we have a number_list. So if we have 30 00:01:44,130 --> 00:01:46,320 a number_list, we're going to use a number, okay. 31 00:01:46,320 --> 00:01:48,270 Because why do we have a number_list we have 32 00:01:48,300 --> 00:01:52,680 numbers. for number in number_list, print number. 33 00:01:52,950 --> 00:01:56,130 Let's run that. And you can see we print all the 34 00:01:56,130 --> 00:01:59,610 elements, okay, in the list. Now you can do for 35 00:01:59,610 --> 00:02:04,290 example, if number is lower, strictly lower than 36 00:02:04,290 --> 00:02:11,670 zero, let's say print number is negative. You 37 00:02:11,670 --> 00:02:15,210 could also add an else to say the number is 38 00:02:15,210 --> 00:02:18,540 positive, let's run that. So you can see we have 39 00:02:18,570 --> 00:02:22,140 3, 5, 8, 12, -3, and the number is negative, 40 00:02:22,320 --> 00:02:25,560 -7, number is negative. Okay, just to show 41 00:02:25,560 --> 00:02:28,530 you that you can combine conditions and loops, 42 00:02:28,530 --> 00:02:31,650 okay. Also, you can use an if inside of for, 43 00:02:31,680 --> 00:02:34,410 you could use another for inside that if or a 44 00:02:34,410 --> 00:02:36,840 while or whatever you want. Okay, so you can 45 00:02:36,840 --> 00:02:40,320 combine them between each other. And well this as 46 00:02:40,320 --> 00:02:43,230 you can see, this is very convenient way to go 47 00:02:43,260 --> 00:02:46,980 through an lists. Okay, and to recap, as you can 48 00:02:46,980 --> 00:02:50,730 see, combining a for loop here with a list is an 49 00:02:50,760 --> 00:02:54,240 extremely powerful combination. You just need one 50 00:02:54,240 --> 00:02:56,970 line of code to do that here. And then you can 51 00:02:56,970 --> 00:03:00,870 write a block of instructions to apply for each 52 00:03:00,900 --> 00:03:04,020 element on the list. And this you're going to use 53 00:03:04,020 --> 00:03:07,542 it quite often in all your future programs.