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