1
00:00:01,340 --> 00:00:07,640
Hello will come again in this lesson you will be talking about four loops for loops are essentially

2
00:00:07,640 --> 00:00:13,690
a way for us to repeat a certain task a certain number of times.

3
00:00:13,700 --> 00:00:18,850
So if you want to do something 10 times or 20 times 100 times we use four loops for it.

4
00:00:18,860 --> 00:00:22,340
And that helps us with a variety of situations.

5
00:00:22,340 --> 00:00:29,720
Imagine if you're you know downloading the user from the backend and then our user has either 25 pictures

6
00:00:29,770 --> 00:00:34,360
and you want to do this thing 25 times or any similar situation.

7
00:00:34,370 --> 00:00:40,940
You will soon see that in every program that you write and every app that you write you use hundreds

8
00:00:40,940 --> 00:00:46,000
of wardrobe simply because that scene or that's hard as as often as they are used.

9
00:00:46,040 --> 00:00:52,220
They're very similar to if else statements are part of the control flow that let us do something and

10
00:00:52,220 --> 00:00:55,700
then based on a condition they continue or they stop.

11
00:00:55,700 --> 00:01:00,970
So just go ahead and see that in practice I'm going to jump into ex-cult.

12
00:01:01,040 --> 00:01:07,360
I'm going to close the previous project I'm going to say is one is for loops.

13
00:01:07,370 --> 00:01:09,680
Command line commands to

14
00:01:13,830 --> 00:01:20,360
and they're essentially to put together a method for writing a four to one type of loop.

15
00:01:20,360 --> 00:01:24,260
It runs based on a certain number of bytes ration.

16
00:01:24,260 --> 00:01:32,510
So you say run it for 10 times or 20 times the other type tells you to run for based on the number of

17
00:01:32,510 --> 00:01:38,010
elements in an array or a string or a number of elements inside a dictionary.

18
00:01:38,090 --> 00:01:39,450
So on and so forth.

19
00:01:39,470 --> 00:01:41,080
So let's see both of them.

20
00:01:41,360 --> 00:01:53,090
The first one I'm going to say for ends by is 0 until a smaller than 10 plus plus run the ATI and then

21
00:01:53,090 --> 00:01:57,300
every time I'm going to say it's like print Hello.

22
00:01:57,560 --> 00:02:00,880
Let's first see how what the result it produces.

23
00:02:00,890 --> 00:02:03,050
And then I'm going explain how it works.

24
00:02:06,420 --> 00:02:14,460
So if this Opterons or this project runs now we should be able to see Hello hello hello hello hello

25
00:02:14,490 --> 00:02:15,100
hello hello.

26
00:02:15,140 --> 00:02:17,340
Ten times versing Hello.

27
00:02:17,780 --> 00:02:25,190
So the way it's working is it saying there is a condition or must be below 10 and they're saying well

28
00:02:25,610 --> 00:02:29,270
what does the I start from it says I ask thoughts from zero.

29
00:02:29,460 --> 00:02:32,750
If it starts from zero is zero below 10.

30
00:02:32,750 --> 00:02:37,530
Yes let's go and do this and then it says now add 1 to our.

31
00:02:37,550 --> 00:02:40,750
So I becomes the one is the one below 10.

32
00:02:40,760 --> 00:02:42,040
Yes it is.

33
00:02:42,170 --> 00:02:49,640
Does this one keeps going on and on and on until let's say he is 8 and is saying is 8 is still below

34
00:02:49,640 --> 00:02:50,320
10.

35
00:02:50,360 --> 00:02:58,990
Yes it is then run this one says at one to it becomes nine the smaller And then this happens then nine

36
00:02:59,000 --> 00:03:03,480
adds one to itself it becomes 10 is 10 below 10.

37
00:03:03,560 --> 00:03:04,470
No it is not.

38
00:03:04,470 --> 00:03:10,310
So this is not going to happen anymore more and we end up in this next line of whatever it is.

39
00:03:10,310 --> 00:03:17,070
So this follow loop essentially happens and goes through all of its hydration until we get here.

40
00:03:17,090 --> 00:03:28,430
Now what if I want to print from either or 25 to 80 I could say and Aslaug what whatever you find integer

41
00:03:28,430 --> 00:03:32,690
type in itself thats an integer right.

42
00:03:32,750 --> 00:03:41,300
So is going to print 25 to 79 like the other relational operators if you want to include 80 you could

43
00:03:41,300 --> 00:03:45,920
just say until it is smaller or equal to 80.

44
00:03:45,950 --> 00:03:53,410
So if you have an equal sign in there now 80 is going to be included in our in our iteration as a starting

45
00:03:53,410 --> 00:03:55,600
gain from zero or two.

46
00:03:55,730 --> 00:03:59,960
Let's say 10 and now this is going to happen 11 times.

47
00:03:59,960 --> 00:04:06,590
I just want to say whatever that you are trying to do in here for 11 times which in this case is just

48
00:04:06,590 --> 00:04:07,910
printing the eye.

49
00:04:08,090 --> 00:04:11,380
You should also remember that it is again arbitrary.

50
00:04:11,390 --> 00:04:13,850
You can name it whatever you like.

51
00:04:14,000 --> 00:04:19,660
The same may in and then that becomes and as well.

52
00:04:19,660 --> 00:04:21,400
And then this becomes an.

53
00:04:21,620 --> 00:04:28,130
So we think that gain or we run again because I see the same thing a lot of times people actually call

54
00:04:28,130 --> 00:04:29,600
these counters.

55
00:04:29,720 --> 00:04:39,320
So between counter zero counters more than 10 counter plus plus Prange counter for the kind of game

56
00:04:39,320 --> 00:04:41,210
we see the same result.

57
00:04:41,210 --> 00:04:46,410
Now let me revert back to you which is a more common way of writing it.

58
00:04:46,540 --> 00:04:48,800
I want to explain another thing for you.

59
00:04:49,040 --> 00:04:56,000
This thing in here if you remember from one of the previous lessons this is incrementing I buy one.

60
00:04:56,130 --> 00:05:01,810
So is going 0 1 2 3 until it is a smaller or equal 10 and then it gets to 11.

61
00:05:01,910 --> 00:05:04,810
This fall finishes what people want it to go.

62
00:05:04,820 --> 00:05:11,220
Every other one whatever if want it to go on lead to even numbers I would say plus equal to.

63
00:05:11,390 --> 00:05:20,120
So instead of just adding 1 I would say I'd go to the to treat a treats for increments to every time.

64
00:05:20,430 --> 00:05:24,440
Let's see that it should print 0 2 4 6 8 10.

65
00:05:24,440 --> 00:05:26,300
Just like what we expected.

66
00:05:26,300 --> 00:05:27,310
So that's another way.

67
00:05:27,320 --> 00:05:31,490
Another thing to keep in mind that the patient doesn't have to go.

68
00:05:31,490 --> 00:05:37,250
One other time even though most likely that is what you want and that's what we usually do.

69
00:05:37,280 --> 00:05:38,970
You go 0 1 2 3 4.

70
00:05:38,990 --> 00:05:40,200
We go in or there.

71
00:05:40,310 --> 00:05:44,370
You could if you wanted to jump every turn to 1 or be 51.

72
00:05:44,380 --> 00:05:47,060
If that's something that that you might need.

73
00:05:47,390 --> 00:05:52,240
Now with that in mind let's move on to another type of 42.

74
00:05:52,340 --> 00:05:56,850
So this what we call it a four new merge.

75
00:05:57,110 --> 00:06:03,170
And now let's go ahead and do 4 in that see four in the works.

76
00:06:03,170 --> 00:06:08,210
I think we saw something like this in one of our previous lessons because we needed to.

77
00:06:08,390 --> 00:06:08,710
Yes.

78
00:06:08,710 --> 00:06:15,110
When we were doing sets we saw that but let's see them once again and ask are they going to call this

79
00:06:15,110 --> 00:06:19,580
one my array is on and this are a lock.

80
00:06:20,110 --> 00:06:30,560
And in it with objects and the objects are let's say Wednesday and then there's another irrelevant object

81
00:06:30,560 --> 00:06:32,090
called Max.

82
00:06:32,270 --> 00:06:36,980
And then there is another object called by us.

83
00:06:36,980 --> 00:06:43,220
And then there's another object called Friday and there's so many random objects that they seemingly

84
00:06:43,340 --> 00:06:45,200
don't have any correlation with each other.

85
00:06:45,200 --> 00:06:49,370
They don't have to have it inside the pause at the end.

86
00:06:49,370 --> 00:06:56,140
We have a name that says this is the end of my Airey and I forgot the one bracket in here.

87
00:06:56,370 --> 00:06:59,830
Like I said it's a very good practice if you stack them like this.

88
00:06:59,900 --> 00:07:03,320
So you actually can see them quite clearly.

89
00:07:03,350 --> 00:07:07,740
So what if I want it to go to the objects in this array.

90
00:07:07,880 --> 00:07:13,820
So let's write that I'm going to say for instance is zero.

91
00:07:13,990 --> 00:07:14,900
And these are.

92
00:07:14,990 --> 00:07:16,390
It is a smaller.

93
00:07:16,580 --> 00:07:21,720
So what should be a smaller from let's say in my array there is 1 2 3 4 5.

94
00:07:21,730 --> 00:07:25,570
So I could see a smaller than five which obviously means zero.

95
00:07:25,580 --> 00:07:27,810
One two three and four.

96
00:07:27,860 --> 00:07:29,210
That's one way of doing it.

97
00:07:29,210 --> 00:07:33,390
The other one would be my array doth count.

98
00:07:33,410 --> 00:07:37,590
So it always depends on my array of course.

99
00:07:37,610 --> 00:07:38,080
All right.

100
00:07:38,120 --> 00:07:40,930
Plus plus increments.

101
00:07:41,210 --> 00:07:48,880
And then you might incrementation in my area I'm going in my for loop I'm going to say and like are.

102
00:07:48,950 --> 00:07:53,460
This is for instance or whatever you find.

103
00:07:53,510 --> 00:07:55,330
What is it that we're looking for.

104
00:07:55,340 --> 00:07:59,360
Why are they not like that.

105
00:07:59,440 --> 00:08:01,020
I've checked that index.

106
00:08:01,020 --> 00:08:03,480
I let me clear this one.

107
00:08:03,600 --> 00:08:08,090
Or let me just comment it out and then I'll explain this once again.

108
00:08:08,110 --> 00:08:09,830
Let me see what we get.

109
00:08:10,930 --> 00:08:17,260
So this is Wednesday math Iowas Friday and Saturday so it's saying go between zero and the count of

110
00:08:17,260 --> 00:08:20,980
the aere increment one at the time each time.

111
00:08:20,990 --> 00:08:29,440
Print this part and whatever you find and then go to my array find the object that that index.

112
00:08:29,440 --> 00:08:39,190
So if I 0 my array 0 if I use one my array one is eyes to my array to so on and so forth.

113
00:08:39,190 --> 00:08:42,690
So this goes through the array and finds all of the objects.

114
00:08:42,700 --> 00:08:49,130
However I told you I'm going to show you another way for doing it not in numeric for loop which you're

115
00:08:49,180 --> 00:08:54,130
again doing in here so that other wave would be like this.

116
00:08:54,370 --> 00:09:05,690
I'm going to say for NSA string any for each or whatever you want to call it in my.

117
00:09:06,550 --> 00:09:12,940
It's means go to my array for objects of the type in the string go through them.

118
00:09:12,940 --> 00:09:19,400
One other time and then place each of them as each call each of them each.

119
00:09:19,410 --> 00:09:22,800
Or let's say in so it says go through my array.

120
00:09:22,810 --> 00:09:24,220
One other time.

121
00:09:24,280 --> 00:09:25,860
Call them and me.

122
00:09:25,990 --> 00:09:27,270
And then what do you want to do with it.

123
00:09:27,280 --> 00:09:32,080
I want to say and it's like whatever you find in any.

124
00:09:32,080 --> 00:09:35,700
So it's saying go through the array one item at a time.

125
00:09:35,740 --> 00:09:40,830
As long as there is a string one item at the time call them any so.

126
00:09:40,880 --> 00:09:41,510
Annie.

127
00:09:41,510 --> 00:09:42,200
Annie.

128
00:09:42,200 --> 00:09:42,880
Annie.

129
00:09:42,880 --> 00:09:43,810
ANNIE.

130
00:09:43,810 --> 00:09:44,940
And any.

131
00:09:44,950 --> 00:09:46,260
And then preinstall.

132
00:09:46,480 --> 00:09:47,920
Let's see what we get if we do that.

133
00:09:47,950 --> 00:09:54,160
If I run this application now we shouldn't get Wednesday Mantz I was Friday on Saturday exactly the

134
00:09:54,190 --> 00:09:57,040
way that they are in here.

135
00:09:57,250 --> 00:09:58,600
So that's about that.

136
00:09:58,610 --> 00:10:01,120
A quick recap.

137
00:10:01,120 --> 00:10:07,490
We do four loops and we want to repeat something a certain number of times we start from summer and

138
00:10:07,500 --> 00:10:08,170
summer.

139
00:10:08,170 --> 00:10:10,050
Remember what we want to include.

140
00:10:10,050 --> 00:10:12,870
The last one or the one in the last one.

141
00:10:13,110 --> 00:10:18,970
We can increment with different ways incrementing one other time when you're printing several other

142
00:10:18,970 --> 00:10:27,970
time and you could use for in loops we could use it for a certain type of object in whatever object

143
00:10:27,970 --> 00:10:33,820
we're looking for and then print the values that we want or do whatever we want to do with those values.

144
00:10:33,820 --> 00:10:39,830
One of the things that we for instance we could do in here is we could say for any object in my array

145
00:10:39,940 --> 00:10:42,000
Let's see if there is a Monday.

146
00:10:42,090 --> 00:10:51,560
So I'm going to say for any in my array if any is equal to a string of Monday Monday.

147
00:10:52,080 --> 00:10:57,580
If that is the case then and Aslaug Monday is there.

148
00:10:57,960 --> 00:11:04,380
So if you're searching for a certain item you could do it like this and say go through this if it is

149
00:11:04,380 --> 00:11:05,150
there printed.

150
00:11:05,160 --> 00:11:08,190
Obviously Monday is not there now and he's not going to print it.

151
00:11:08,340 --> 00:11:14,190
But if I was searching for oils anyway withdrawn this would say for any of them.

152
00:11:14,220 --> 00:11:14,810
Yes.

153
00:11:14,860 --> 00:11:18,750
Was is so perfect with the money.

154
00:11:18,780 --> 00:11:20,800
Let's move on to our next lesson.
