1
00:00:02,140 --> 00:00:05,070
Pay everyone Mark Price you're at death's slopes.

2
00:00:05,280 --> 00:00:12,480
And today we're going to learn how to work with loops and you've learned a little bit about arrays and

3
00:00:12,530 --> 00:00:18,740
you're going to see how loops and arrays go hand-in-hand together go ahead and create a new playground

4
00:00:19,010 --> 00:00:29,520
file new playground and let's call this loop the loops because it sounds so much fun.

5
00:00:30,780 --> 00:00:32,940
Animals save it right here.

6
00:00:33,060 --> 00:00:37,060
Perfect.

7
00:00:37,500 --> 00:00:38,340
OK.

8
00:00:38,940 --> 00:00:42,990
So in order to appreciate and understand the loop Let's talk about some of the problems that we run

9
00:00:42,990 --> 00:00:45,260
into when we don't use loops.

10
00:00:45,480 --> 00:00:46,290
OK.

11
00:00:46,290 --> 00:00:52,150
And we've kind of used this before this scenario in working with arrays so let's do the same thing now.

12
00:00:52,230 --> 00:00:59,700
So we've got employees or rather we've got employees who have salary's bar employee one salary.

13
00:00:59,770 --> 00:01:00,230
Right.

14
00:01:00,320 --> 00:01:04,050
So you've got four employees employees each with their own salary.

15
00:01:04,050 --> 00:01:13,830
Forty five thousand dollars for employee 1 bar employee 2 salary equals one hundred thousand dollars.

16
00:01:13,860 --> 00:01:26,700
Our employee three salary equals fifty four thousand dollars and bar employee for salary equals $20000.

17
00:01:27,420 --> 00:01:29,290
OK so we've got four different employees here.

18
00:01:29,310 --> 00:01:34,860
All right now let's say that we had a really good year at the company.

19
00:01:34,920 --> 00:01:35,260
OK.

20
00:01:35,280 --> 00:01:37,760
And we want to give every employee a raise.

21
00:01:37,800 --> 00:01:38,970
So we need the app to do that.

22
00:01:38,970 --> 00:01:42,910
You know we were a big company we need to make sure that we can automate some things.

23
00:01:42,930 --> 00:01:48,200
So we're writing an app that allows us to give instant salary increases to employees.

24
00:01:48,570 --> 00:01:50,020
So how do we do that.

25
00:01:52,020 --> 00:01:56,770
Let's say also that we need to give them a certain percentage of a salary raise.

26
00:01:56,760 --> 00:01:57,800
So listen to that as well.

27
00:01:57,810 --> 00:01:59,970
So when I say employee one's salary

28
00:02:08,000 --> 00:02:17,340
employee one salary equals employee one salary plus employee one salary is 0.1 0.

29
00:02:17,590 --> 00:02:20,840
OK so we're doing some basic high school math here.

30
00:02:20,840 --> 00:02:23,390
We're taking the salary of the first employee.

31
00:02:23,390 --> 00:02:29,360
Multiplying it by a decimal point 10 which is 10 percent so we're going to find out what 10 percent

32
00:02:29,360 --> 00:02:34,520
of their existing salary is and then we're going to add it back onto the salary here and store into

33
00:02:34,520 --> 00:02:38,540
employee one salary that's all that's happening we're giving this person a 10 percent increase in their

34
00:02:38,540 --> 00:02:39,030
salary.

35
00:02:39,080 --> 00:02:40,800
And they're very happy about that.

36
00:02:40,870 --> 00:02:42,920
They want any bugs in this app that's for sure.

37
00:02:43,190 --> 00:02:50,000
Especially if it's for your own salary as an employee salary his employee salary plus employees DOLLERY

38
00:02:50,450 --> 00:02:51,900
times 0.1 0.

39
00:02:51,910 --> 00:02:53,430
You're probably thinking to yourself.

40
00:02:53,450 --> 00:02:54,580
All right I get the point Mark.

41
00:02:54,590 --> 00:02:56,900
You don't have to keep writing all this code as is a drag.

42
00:02:57,240 --> 00:03:03,620
I'm going to write it down anyway because you need to really appreciate the pain of doing this kind

43
00:03:03,620 --> 00:03:07,800
of stuff because if you're doing this kind of stuff in your code you're doing it wrong.

44
00:03:07,820 --> 00:03:11,050
There's definitely a better way to code.

45
00:03:11,690 --> 00:03:14,870
This is called code smell when you're like something it doesn't seem right about this.

46
00:03:14,870 --> 00:03:20,640
Well we're also breaking the dry principle here too.

47
00:03:20,870 --> 00:03:22,970
Don't repeat yourself.

48
00:03:23,030 --> 00:03:24,260
All right.

49
00:03:24,260 --> 00:03:28,160
So you've just given every employee here a 10 percent raise right.

50
00:03:28,160 --> 00:03:29,050
That's great.

51
00:03:29,070 --> 00:03:33,940
Now the problem comes in especially when we have like 50 employees or 100 employees.

52
00:03:33,940 --> 00:03:36,140
Are you going to write an app that stores all of this.

53
00:03:36,140 --> 00:03:39,080
Also what if we hire new employees or fire employees.

54
00:03:39,080 --> 00:03:40,880
How do we know how many employees are.

55
00:03:40,880 --> 00:03:45,520
Every time we get a new employee We're going to have to change our code to add the employees in here.

56
00:03:45,530 --> 00:03:47,620
This is not a great way to do things.

57
00:03:47,660 --> 00:03:48,620
Not at all.

58
00:03:48,980 --> 00:03:50,390
Not at all.

59
00:03:50,420 --> 00:03:54,970
And also it's not a good idea to keep this off separately like this as well too.

60
00:03:54,980 --> 00:03:55,980
So this is bad.

61
00:03:56,020 --> 00:03:56,290
OK.

62
00:03:56,300 --> 00:03:58,040
This is the bad way.

63
00:03:58,160 --> 00:03:59,610
Bad way.

64
00:03:59,690 --> 00:04:00,030
All right.

65
00:04:00,050 --> 00:04:01,230
Let's clean some things up.

66
00:04:01,280 --> 00:04:06,920
You know let's put these employees salaries in the interface of our salaries equals and then we can

67
00:04:06,930 --> 00:04:11,890
just do some copying and pasting here so paste you know this is an array.

68
00:04:12,000 --> 00:04:13,160
We've talked about this before.

69
00:04:13,160 --> 00:04:21,450
Command c command B and C is copying and pasting here.

70
00:04:22,370 --> 00:04:27,460
So there's our array of salary's so Elissa's is better.

71
00:04:27,470 --> 00:04:32,610
This is mo better putting in an array.

72
00:04:32,850 --> 00:04:40,090
Ok but how would we go through these and add 10 percent each person's salary.

73
00:04:40,100 --> 00:04:50,780
Well it would look something like this would be salary's zero pay equals or NSA salaries zero.

74
00:04:50,930 --> 00:05:03,650
The first salary out here plus salaries zero times zero point zero time and then same day salaries one

75
00:05:03,710 --> 00:05:12,820
equals salaries one plus salaries one times 0.0 etc. etc..

76
00:05:13,070 --> 00:05:13,900
The other two.

77
00:05:14,210 --> 00:05:19,240
Okay so is this any better than this.

78
00:05:19,250 --> 00:05:20,040
Not really.

79
00:05:20,060 --> 00:05:21,680
We're still writing lots of code.

80
00:05:21,680 --> 00:05:25,090
So this is definitely better putting in an array versus four different variables.

81
00:05:25,100 --> 00:05:26,320
But this is no good.

82
00:05:26,600 --> 00:05:28,960
This is a lot of manual work and again we don't know.

83
00:05:29,210 --> 00:05:32,350
You know I'm putting numbers in here but we don't know how many employees are actually in the list.

84
00:05:32,430 --> 00:05:35,990
You know it's going to come into the app and we wouldn't know unless we count them on and changed our

85
00:05:35,990 --> 00:05:37,600
code which is you don't do that.

86
00:05:37,600 --> 00:05:42,770
Nobody rewrites code and does all that stuff manually based on some condition in the real world.

87
00:05:42,950 --> 00:05:44,510
So how do we solve this problem.

88
00:05:44,600 --> 00:05:50,300
Well we can solve this problem that's making our life so miserable right now by using a loop and let's

89
00:05:50,300 --> 00:05:52,530
create our very first loop.

90
00:05:52,730 --> 00:05:55,410
We're going to do a a while loop.

91
00:05:55,610 --> 00:05:56,530
OK.

92
00:05:56,600 --> 00:05:58,610
So we're going to say var X equals zero.

93
00:05:58,610 --> 00:06:00,330
This is going to be an index.

94
00:06:00,350 --> 00:06:08,390
And then we're going to say repeat while X is less than salary's does count

95
00:06:13,100 --> 00:06:17,810
more and say X plus equals 1 OK.

96
00:06:18,270 --> 00:06:21,150
So what is going on here.

97
00:06:21,750 --> 00:06:25,440
Well look over here on the right it says it ran this loop four times.

98
00:06:25,560 --> 00:06:26,750
So here's the syntax.

99
00:06:26,820 --> 00:06:28,660
The keyword is repeat.

100
00:06:28,830 --> 00:06:29,730
OK.

101
00:06:29,760 --> 00:06:30,410
Repeat.

102
00:06:30,600 --> 00:06:38,730
And then a opening bracket and closing bracket inside were incrementing X by 1.

103
00:06:38,730 --> 00:06:40,280
It's a variable of type int.

104
00:06:40,530 --> 00:06:48,180
And then while X is less than stellar is that count so every loop in programming will repeat itself

105
00:06:48,270 --> 00:06:50,240
until some condition is met.

106
00:06:50,310 --> 00:06:52,020
OK that's what you need to remember it doesn't.

107
00:06:52,020 --> 00:06:57,810
Don't think of the syntax rules are different types of loops loops will repeat until some condition

108
00:06:57,930 --> 00:06:59,040
is met.

109
00:06:59,250 --> 00:07:05,120
And in this case here in the parentheses while X is less than salary's does count.

110
00:07:05,330 --> 00:07:10,400
Let's see how many items are in salary's 1 2 3 4.

111
00:07:10,410 --> 00:07:14,280
So while x is less than 4 Well it starts at zero.

112
00:07:14,280 --> 00:07:15,820
So this is what's going to happen.

113
00:07:15,990 --> 00:07:19,410
This loop is going to be run once for sure no matter what.

114
00:07:19,410 --> 00:07:24,650
And X is now equal to one X plus equals 1.

115
00:07:24,700 --> 00:07:29,490
And then it says while X is less than Sollars accounts while one is less than that Zackham OK it is

116
00:07:29,490 --> 00:07:34,800
still less than salary's that count so it's going to go through again from top to bottom over and over

117
00:07:34,800 --> 00:07:39,240
and over again until X is now equal to 4.

118
00:07:39,240 --> 00:07:44,760
So as well as some point this will increase X to 4 and then this will no longer be true because 4 is

119
00:07:44,760 --> 00:07:47,960
not less than sellers that count the fours not less than four is it.

120
00:07:48,000 --> 00:07:50,730
No 4 is equal to four.

121
00:07:50,730 --> 00:07:51,230
OK.

122
00:07:51,300 --> 00:07:56,490
So there's a difference here if I was to say less than or equal to it would run five times but we don't

123
00:07:56,490 --> 00:08:02,790
want it to run five times because that would crash our our application if we're accessing elements out

124
00:08:02,790 --> 00:08:03,770
of this array.

125
00:08:04,080 --> 00:08:08,110
So how do we use this loop to solve our problem.

126
00:08:08,910 --> 00:08:13,550
Well let me tell you there Bob we first crash x.

127
00:08:13,930 --> 00:08:15,140
That's the right thing to do.

128
00:08:17,550 --> 00:08:20,660
Let's open up X code again.

129
00:08:20,850 --> 00:08:21,950
Are you ready.

130
00:08:21,970 --> 00:08:22,920
So here goes.

131
00:08:22,920 --> 00:08:33,480
Salary's X equal salary is X plus salaries X times zero.

132
00:08:33,500 --> 00:08:35,320
Opponent 1 0.

133
00:08:36,230 --> 00:08:38,690
OK well this is interesting.

134
00:08:39,090 --> 00:08:42,330
What's going on here Mark why are you putting an X inside of an array that doesn't make any sense.

135
00:08:42,330 --> 00:08:43,740
I thought a raise couldn't take strings.

136
00:08:43,740 --> 00:08:45,320
Well it's not a sure thing right.

137
00:08:45,330 --> 00:08:46,830
It's an INT.

138
00:08:46,980 --> 00:08:54,040
And this is also an you access elements out of your array using it ok you put in the subscript here.

139
00:08:54,180 --> 00:08:56,220
We want the first element or the second element.

140
00:08:56,430 --> 00:09:00,760
So the same things happening here we have a variable that represents our index.

141
00:09:00,780 --> 00:09:07,080
So what we could also have done is called this index that makes more sense to you.

142
00:09:07,110 --> 00:09:08,370
And then what you can do.

143
00:09:08,670 --> 00:09:10,610
You can just pass the index here instead.

144
00:09:10,720 --> 00:09:12,300
It's not that though.

145
00:09:14,520 --> 00:09:18,270
And then right here and right here.

146
00:09:18,360 --> 00:09:20,980
So a little more wordy but it makes more sense now.

147
00:09:20,990 --> 00:09:24,360
So we have an index where passing in the index and that's giving us the element.

148
00:09:24,360 --> 00:09:26,800
So it's going to repeat and grow items out of that.

149
00:09:27,030 --> 00:09:28,860
So let's look at this again.

150
00:09:29,550 --> 00:09:34,950
Salary's index Well if it's the first 10 through index is equal to zero sorgen to grab forty five thousand.

151
00:09:34,980 --> 00:09:39,950
So we're seeing this slide here is equal to salary's index.

152
00:09:40,020 --> 00:09:46,730
So it's equal to 45000 plus 45000 times point 1 0.

153
00:09:46,900 --> 00:09:47,410
OK.

154
00:09:47,460 --> 00:09:49,130
So we're going to take that.

155
00:09:49,510 --> 00:09:54,510
The amount here that 10 percent we're going to add on to 45000 and then we're going to store the result

156
00:09:54,540 --> 00:09:57,400
of this operation here now OK.

157
00:09:57,630 --> 00:10:05,240
And we're going to pass it or as a sign it here into our salaries index into the same spot that we wanted

158
00:10:05,240 --> 00:10:05,680
to.

159
00:10:05,970 --> 00:10:08,090
And so this is cool.

160
00:10:08,100 --> 00:10:14,640
So yeah we've got one two three four five lines of code here versus potentially.

161
00:10:14,880 --> 00:10:17,150
Well let's look at this here.

162
00:10:17,370 --> 00:10:21,840
If we want to do the same thing over here we would have one two three 4 lines of code and 5 year like

163
00:10:21,840 --> 00:10:22,200
haha.

164
00:10:22,210 --> 00:10:25,680
Mark it's not any less code it's the same amount of code that we wrote before.

165
00:10:25,980 --> 00:10:30,210
Well what happens if your company has a lot of employees So

166
00:10:33,300 --> 00:10:36,100
what have has this many employees.

167
00:10:36,860 --> 00:10:37,920
There's 28 employees.

168
00:10:37,920 --> 00:10:44,850
Now if I wanted to do this down here I'd have like 20 lines of code that's no good.

169
00:10:44,850 --> 00:10:48,140
Plus this whereas this will always stay a 5.

170
00:10:48,300 --> 00:10:50,000
Even if I had a million employees.

171
00:10:50,070 --> 00:10:51,960
So we're start to make really good progress here again.

172
00:10:51,960 --> 00:11:00,270
So Lou all the loops going to do is go over and over and over and over again until some condition is

173
00:11:00,270 --> 00:11:00,990
met.

174
00:11:00,990 --> 00:11:04,810
In this case index is less than salaries don't count.

175
00:11:04,960 --> 00:11:12,870
OK if I didn't have this line of code here do you know what we what we would have running here we would

176
00:11:12,870 --> 00:11:14,070
have an infinite loop.

177
00:11:14,070 --> 00:11:15,940
This will eventually crash the program.

178
00:11:16,170 --> 00:11:19,050
Luckily the playground is smart enough to stop it for us.

179
00:11:19,230 --> 00:11:22,620
But if you did something like that in your app you would get an infinite loop.

180
00:11:22,620 --> 00:11:26,750
Your app would and run out of memory and it would crash and new user would give you a one star review.

181
00:11:26,760 --> 00:11:28,900
This developer does not know how to make apps.

182
00:11:29,010 --> 00:11:32,210
So you always have to have a way to get out of a loop.

183
00:11:32,460 --> 00:11:34,680
And it's by meeting the condition.

184
00:11:34,830 --> 00:11:37,840
And so that's why we're increasing the index by 1 each time.

185
00:11:37,860 --> 00:11:39,960
So eventually we can meet the condition.

186
00:11:40,260 --> 00:11:42,840
So that's how loops and arrays go hand-in-hand.

187
00:11:42,840 --> 00:11:47,510
You have a set of data and you can iterate through the data with a loop.

188
00:11:47,760 --> 00:11:49,570
Does that make sense.

189
00:11:49,580 --> 00:11:50,420
Is anyone confused.

190
00:11:50,430 --> 00:11:56,880
Because if you are what I want to do is posit video you can watch this portion again or you can go online

191
00:11:56,880 --> 00:12:02,730
to do some research on how to loops work in programming and making some more under the hood.

192
00:12:03,390 --> 00:12:06,540
Computer science aspects and theory about it.

193
00:12:06,670 --> 00:12:06,950
OK.

194
00:12:06,960 --> 00:12:10,250
So this is a repeat while it now you're not going to use is a whole lot.

195
00:12:10,260 --> 00:12:15,030
I wanted to show you the repeat while loop because it's very wordy and it makes sense when you look

196
00:12:15,030 --> 00:12:20,510
at it the loop that you're probably going to use more so is a for loop.

197
00:12:20,820 --> 00:12:22,740
Let's do that next.

198
00:12:23,670 --> 00:12:24,710
Let's bring it down here.

199
00:12:24,750 --> 00:12:25,150
OK.

200
00:12:25,290 --> 00:12:29,000
So we're in right the exact same code with even less lines of code which is cool.

201
00:12:29,010 --> 00:12:39,870
So for X or let's say I to represent index in zero dot dot less than salary's dot count.

202
00:12:39,930 --> 00:12:45,750
And then what we'll do is we'll just copy this one line of code here and paste it here.

203
00:12:45,750 --> 00:12:48,910
So now we're doing the exact same thing.

204
00:12:48,990 --> 00:12:53,410
This should be in the index.

205
00:12:54,140 --> 00:12:58,310
We're doing the exact same thing here and three lines of code that we do with five lines of code so

206
00:12:58,310 --> 00:12:58,850
it's smaller.

207
00:12:58,850 --> 00:13:00,760
So let's talk about what's happening.

208
00:13:00,920 --> 00:13:07,170
So for meaning given or for each k is.

209
00:13:07,280 --> 00:13:08,990
This is called a for in loop.

210
00:13:09,050 --> 00:13:10,990
As you can see the four in the end.

211
00:13:11,540 --> 00:13:18,300
So for I in zero dot dot less than Sollars accounts what we're doing here is we're specifying a range.

212
00:13:18,470 --> 00:13:24,610
OK we're saying start at zero and go all the way to salary's that count which is currently 28.

213
00:13:24,770 --> 00:13:29,420
But we need to be minus one because arrays start at zero which is why we use the less than sign.

214
00:13:29,420 --> 00:13:33,400
So Dot Dot less than you know so we don't put a space before this or a space after.

215
00:13:33,520 --> 00:13:34,060
OK.

216
00:13:34,250 --> 00:13:42,500
So between 0 and salary's that counts between 0 and 27 and then we go through and we run this and it's

217
00:13:42,500 --> 00:13:44,520
going to do the exact same thing as this.

218
00:13:44,550 --> 00:13:50,570
OK and if you're confused at all I mean just do we write this up in even simpler terms so for let's

219
00:13:50,570 --> 00:13:59,720
say X in one dot dot dot five that's just print index.

220
00:13:59,990 --> 00:14:02,810
We're going to say is equal to the X

221
00:14:06,590 --> 00:14:13,660
get five times I hear as you can see it printed out five times for X in one through five.

222
00:14:13,660 --> 00:14:15,820
So what just happened here.

223
00:14:15,970 --> 00:14:17,240
It's inclusive.

224
00:14:17,290 --> 00:14:17,710
OK.

225
00:14:17,710 --> 00:14:21,250
So it included the one and it included the five and everything in between.

226
00:14:21,340 --> 00:14:24,570
So this is a range you can call it a sequence you can color range.

227
00:14:24,580 --> 00:14:27,850
So it's a sequence of numbers or range and that's the condition.

228
00:14:27,850 --> 00:14:35,380
So for for every You're going to run this loop for every item in this range between 1 and 5 or including

229
00:14:35,380 --> 00:14:37,290
one in 5 inclusive.

230
00:14:37,300 --> 00:14:38,260
Same thing here.

231
00:14:38,560 --> 00:14:39,340
OK.

232
00:14:39,760 --> 00:14:45,430
Between 0 and salaries that count are less than sellers account so that means 27.

233
00:14:45,600 --> 00:14:46,070
OK.

234
00:14:46,180 --> 00:14:51,080
So this one is inclusive This one's exclusive of the number that you put here.

235
00:14:51,220 --> 00:14:51,420
OK.

236
00:14:51,430 --> 00:14:59,490
So in this case here listen do the same thing over here again for the in one thought less than five

237
00:15:00,340 --> 00:15:09,430
in print and X Z and then we'll go ahead and put Z in here.

238
00:15:10,360 --> 00:15:10,610
OK.

239
00:15:10,630 --> 00:15:16,640
So in this case it only ran 1 2 3 4 K so this was Xclusive it did not include the 5 because we have

240
00:15:16,640 --> 00:15:17,790
the less than sign there.

241
00:15:17,940 --> 00:15:18,870
OK.

242
00:15:18,970 --> 00:15:24,930
And what's happening is every time it goes through this loop it passes that value of this range here.

243
00:15:25,000 --> 00:15:30,840
The current iteration of that range it passes it here into this constant this number cannot be changed.

244
00:15:30,850 --> 00:15:33,840
It passes it in here so you can use it for whatever you want.

245
00:15:33,850 --> 00:15:38,490
In our case here we're using it each time to access the element in the array.

246
00:15:38,500 --> 00:15:44,250
So in this case it's going to run this code 28 times between 0 and 27.

247
00:15:44,260 --> 00:15:50,050
It's going to pass that number into every single time 0 1 2 3 4 or 5 and then you can use those numbers

248
00:15:50,170 --> 00:15:54,700
on your array elements which is pretty cool which is why we do salary's don't count.

249
00:15:54,700 --> 00:15:59,430
We get the total length of the array as our maximum number and then we run through it.

250
00:15:59,440 --> 00:16:03,330
So we know it's going to stop once it gets us where we need to be.

251
00:16:03,430 --> 00:16:06,210
So we don't have to do this kind of junk anymore.

252
00:16:06,280 --> 00:16:08,120
We don't have to do this kind of junk anymore.

253
00:16:08,380 --> 00:16:13,570
You're going to have an array of salaries and then you can run loops to get information out of those

254
00:16:13,570 --> 00:16:17,010
salaries or out of that array which is pretty cool.

255
00:16:17,020 --> 00:16:20,350
Now loops can take a long time to understand if this is really confusing for you.

256
00:16:20,390 --> 00:16:21,400
It's OK.

257
00:16:21,490 --> 00:16:23,870
This is normal to be confused.

258
00:16:23,890 --> 00:16:27,010
All you need to know as a beginner is how do you use these tools.

259
00:16:27,010 --> 00:16:30,670
Because as you get better at them you're going to get you're going to understand what's going on under

260
00:16:30,670 --> 00:16:32,430
the hood and how these things work.

261
00:16:32,440 --> 00:16:39,250
OK so what we've done here is we've created a while loop and we've created three four in loops.

262
00:16:39,280 --> 00:16:43,750
There's one more loop I want to talk about and it's a for each loop.

263
00:16:44,140 --> 00:16:44,970
OK.

264
00:16:45,580 --> 00:16:50,340
And it's technically a for loop but I'll show you why it might make sense to word it.

265
00:16:50,350 --> 00:17:00,220
As for each so for salary in salaries they print salary.

266
00:17:00,620 --> 00:17:04,140
So let's say you want to create something that goes for all the salaries and prints them up.

267
00:17:04,180 --> 00:17:05,400
OK.

268
00:17:06,640 --> 00:17:12,690
So what we're doing here is very similar to this for in loop but there is no range.

269
00:17:12,850 --> 00:17:13,220
OK.

270
00:17:13,220 --> 00:17:20,190
So what we're doing here is we're saying for each visualizes your mind for each item in this array run

271
00:17:20,190 --> 00:17:23,440
a loop so that's the condition for every item that's in this array.

272
00:17:23,440 --> 00:17:24,390
Run this loop.

273
00:17:24,400 --> 00:17:29,700
So in our case here for every salary that is inside the salaries array.

274
00:17:30,100 --> 00:17:32,990
OK print salary.

275
00:17:33,010 --> 00:17:37,640
So what it does is it it skips some things for you it it takes off this heavy lifting for you.

276
00:17:37,660 --> 00:17:39,940
Grabbing the index it says don't worry about that.

277
00:17:39,970 --> 00:17:40,650
We'll do that for you.

278
00:17:40,660 --> 00:17:46,940
So it grabs the item out of the array for you automatically and sticks it here in it.

279
00:17:46,960 --> 00:17:52,510
How cool is that sticks out for you right there ready for you to use without having to grab it out of

280
00:17:52,510 --> 00:17:54,220
the out of the tray itself.

281
00:17:54,220 --> 00:17:57,670
And then we just we're just in this case we're just printing it right.

282
00:17:57,700 --> 00:18:00,420
Pretty good stuff I think.

283
00:18:00,760 --> 00:18:03,170
And so it's the exact same thing as you can see right here.

284
00:18:03,220 --> 00:18:04,890
It's printing up all of these salaries here.

285
00:18:04,890 --> 00:18:09,080
And so this is a for loop as well but may also want to call a For Each loop.

286
00:18:09,150 --> 00:18:09,450
OK.

287
00:18:09,460 --> 00:18:13,840
For each salary in salaries grabs each item out of the array.

288
00:18:13,840 --> 00:18:18,880
One at a time puts in this variable so you can use it and when it gets to the end your loop is done.

289
00:18:18,880 --> 00:18:22,080
So you don't ever have to worry about an infinite loop.

290
00:18:22,090 --> 00:18:28,090
For the most part in this case whereas right here we had to create some condition to get rid of it to

291
00:18:28,090 --> 00:18:29,150
get out of the loop.

292
00:18:29,170 --> 00:18:29,870
OK.

293
00:18:30,280 --> 00:18:32,700
So really cool stuff loops.

294
00:18:32,740 --> 00:18:36,850
This is what you're going to do most of the time there's a lot more that goes into it and they get trickier

295
00:18:36,850 --> 00:18:37,720
as you go down the line.

296
00:18:37,720 --> 00:18:43,120
But for most of what we'll be doing and for most of what you'll be doing this kind of covers the basics

297
00:18:43,540 --> 00:18:49,600
of what you spend most of your time working on when it comes to loops and arrays.

298
00:18:50,250 --> 00:18:50,940
So that's it.

299
00:18:50,950 --> 00:18:54,030
Mark Price of slopes of dot com see.
