1 00:00:00,790 --> 00:00:01,569 Welcome back. 2 00:00:01,839 --> 00:00:08,140 And this video we are going to check out for loops and they are used to iterate through rangers' arrays, 3 00:00:08,140 --> 00:00:12,280 collections or anything that provides an iterator. 4 00:00:12,550 --> 00:00:17,020 And you will learn about iterates arrays, ranges and collections in the future lectures. 5 00:00:17,260 --> 00:00:18,730 So no worries there. 6 00:00:18,910 --> 00:00:28,960 But basically, it's just a set of values that are stored in one construct or in one type of data type. 7 00:00:29,020 --> 00:00:35,800 All right, as we've seen, there are multiple different data types such as and double strings and so 8 00:00:35,800 --> 00:00:36,070 forth. 9 00:00:36,070 --> 00:00:42,610 But there are also data types which can store many values at once and their types of collections or 10 00:00:42,850 --> 00:00:43,290 raters. 11 00:00:43,870 --> 00:00:52,630 All right, so what we can do is create four loops as well in codling and a for loop is also very similar 12 00:00:52,630 --> 00:01:01,210 to a wire loop, so we can just go ahead and use to four key words and then number in one dot dot 10 13 00:01:02,170 --> 00:01:03,520 and execute some code. 14 00:01:03,520 --> 00:01:07,750 And I'm just going to execute actually got executed in one line. 15 00:01:08,020 --> 00:01:11,560 Just going to say print number in a string. 16 00:01:11,800 --> 00:01:12,250 All right. 17 00:01:12,820 --> 00:01:21,340 So this for loop here, which we have in three lines, so to see is the same thing as our wire loop 18 00:01:21,340 --> 00:01:24,470 that we had here where we needed to create a variable. 19 00:01:24,490 --> 00:01:31,390 Then we had the condition, then we did the execution of something or write something on the screen, 20 00:01:31,780 --> 00:01:36,940 and then we needed to take care of the condition at one point not being met anymore. 21 00:01:37,360 --> 00:01:38,110 And that's it. 22 00:01:38,680 --> 00:01:39,040 All right. 23 00:01:39,040 --> 00:01:42,970 But now we sum everything up, so it's a lot shorter. 24 00:01:43,360 --> 00:01:50,470 So here it just says for the number which is in this range of one to 10, please execute the code in 25 00:01:50,470 --> 00:01:50,890 the block. 26 00:01:51,070 --> 00:01:56,410 And in our case, we just do something simple where we just say, OK, print the number that you're 27 00:01:56,410 --> 00:01:57,970 currently looking at. 28 00:01:59,070 --> 00:02:06,240 So if we run this, we can see that it just prints one, two, three four and so forth up to the point 29 00:02:06,840 --> 00:02:07,890 where it's 10. 30 00:02:08,039 --> 00:02:09,240 So what a values tent. 31 00:02:09,810 --> 00:02:10,229 All right. 32 00:02:10,440 --> 00:02:13,230 So this is just one way of writing a follow up. 33 00:02:13,500 --> 00:02:15,000 There are other ways as well. 34 00:02:15,090 --> 00:02:22,470 You can also instead of saying them in so and so you can say I in one until 10. 35 00:02:22,920 --> 00:02:29,460 So that will pretty much give us the same result where we, for example, just print I and I'm going 36 00:02:29,460 --> 00:02:31,110 to add an empty space here. 37 00:02:31,920 --> 00:02:32,610 Let's run this. 38 00:02:34,140 --> 00:02:40,570 And we can see that printed the one two, three, four, four and so forth from before from this for 39 00:02:40,590 --> 00:02:40,830 loop. 40 00:02:41,160 --> 00:02:46,280 And then we have this one empty space to empty space and so forth from this forward. 41 00:02:46,440 --> 00:02:48,990 So here we just use this until key word. 42 00:02:49,290 --> 00:02:50,130 What would you say? 43 00:02:51,300 --> 00:02:54,090 I want to have I in a range. 44 00:02:54,180 --> 00:03:02,160 So this here is a range where what says start at one and go up until 10, now it goes the other way 45 00:03:02,160 --> 00:03:02,850 around as well. 46 00:03:03,450 --> 00:03:06,450 You've seen the key words down to so please. 47 00:03:06,750 --> 00:03:11,340 Now go ahead and try to build a for loop, which goes from 10 down to one. 48 00:03:13,720 --> 00:03:14,130 OK. 49 00:03:14,170 --> 00:03:20,380 I hope you tried it because we just used this keyword already, so I thought it would be a great idea 50 00:03:20,710 --> 00:03:24,010 to use it in here is a little challenge. 51 00:03:24,020 --> 00:03:29,710 So for I in 10, down to one. 52 00:03:30,670 --> 00:03:31,190 All right. 53 00:03:31,210 --> 00:03:39,490 And I'm just going to say that there should be a line in between so that we see that this is tied down 54 00:03:39,490 --> 00:03:41,530 to approach here that we had. 55 00:03:44,060 --> 00:03:46,760 And there we are ten, nine, eight and so forth. 56 00:03:47,750 --> 00:03:53,120 So what can you do if you want to have steps of not one, but let's say steps of two? 57 00:03:54,020 --> 00:04:00,490 Well, you can simply add the key word step in here and then say how big the steps should be. 58 00:04:00,530 --> 00:04:09,680 So down to one with the steps of two who run this, then we will see 10, eight, six four two and nothing 59 00:04:09,680 --> 00:04:09,890 else. 60 00:04:10,070 --> 00:04:10,460 That's it. 61 00:04:11,330 --> 00:04:15,920 So there is another way of writing this what we have here. 62 00:04:16,130 --> 00:04:20,420 So this down to approach and in general, four to four loops. 63 00:04:20,779 --> 00:04:29,770 So this is pretty much the same as doing the following as if we had this line here start. 64 00:04:30,020 --> 00:04:31,520 Step two. 65 00:04:32,420 --> 00:04:32,860 OK. 66 00:04:33,260 --> 00:04:38,990 So either you write the form of like this or you can also write the follow up like that where we just 67 00:04:38,990 --> 00:04:41,030 used a slightly different approach. 68 00:04:41,360 --> 00:04:41,750 All right. 69 00:04:41,990 --> 00:04:47,430 But you can, of course, do the same thing for our other four loops up there as well. 70 00:04:47,480 --> 00:04:57,050 So for the second one where we said I in one until 10, we can also say four I in one dot until 10. 71 00:04:58,210 --> 00:05:01,270 Internally, the same thing will happen already. 72 00:05:01,390 --> 00:05:03,220 So these are some examples for for loops. 73 00:05:03,340 --> 00:05:09,490 We're going to use them extensively, especially as soon as we have collections, lists, arrays and 74 00:05:09,490 --> 00:05:12,720 all those kind of cool type of collections. 75 00:05:12,790 --> 00:05:14,350 So see you in the next video.