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