1
00:00:00,390 --> 00:00:03,780
So it's time for two very quick for loop exercises.

2
00:00:03,840 --> 00:00:08,100
And just like the ones before with the wild loops you don't actually have to write any code just yet

3
00:00:08,120 --> 00:00:08,390
.

4
00:00:08,670 --> 00:00:13,590
So I'm going to give you two code fragments and I'd like for you to try and evaluate it mentally without

5
00:00:13,590 --> 00:00:14,620
using the cons..

6
00:00:14,850 --> 00:00:16,140
So here's the first one.

7
00:00:16,140 --> 00:00:21,410
Take a moment pause the video if you need to and then we'll go over the solution.

8
00:00:21,660 --> 00:00:27,160
So at the beginning of this loop a variable is set to zero and the loop is going to run.

9
00:00:27,210 --> 00:00:33,950
While it is less than 16 and every time through we're going to add eight to.

10
00:00:34,260 --> 00:00:37,780
So the first time it's going to be zero and we'll print out 0.

11
00:00:37,950 --> 00:00:39,140
Then we add eight.

12
00:00:39,450 --> 00:00:42,670
So the next time it's eight which is still less than 16.

13
00:00:42,750 --> 00:00:45,940
So we get counted out log 8.

14
00:00:46,080 --> 00:00:49,290
So it prints 0 and 8 and then it adds eight more.

15
00:00:49,290 --> 00:00:54,840
So we end up with I equal to 16 which is no longer less than 16 and we're done.

16
00:00:55,260 --> 00:01:04,850
So let's verify pass that and we get zero and 8.

17
00:01:04,980 --> 00:01:06,420
So here's the second one.

18
00:01:06,420 --> 00:01:08,660
Go ahead take a moment positive he needs to.

19
00:01:08,790 --> 00:01:11,840
And then we'll go over this in just a second.

20
00:01:13,200 --> 00:01:13,690
OK.

21
00:01:13,710 --> 00:01:17,080
So this one you're just a string rather than just numbers.

22
00:01:17,220 --> 00:01:20,190
So we have a string with a bunch of random characters.

23
00:01:20,340 --> 00:01:22,590
Or maybe they're not too random we'll see.

24
00:01:22,590 --> 00:01:30,300
So then we have a for loop with a variable that starts as 1 not 0 and then we're going to keep running

25
00:01:30,300 --> 00:01:36,930
this Loop While itis less like a string and we're going to add two every time not just one.

26
00:01:37,380 --> 00:01:42,600
So the first time through we take I can reprint the character at I from the string.

27
00:01:42,840 --> 00:01:43,810
So I one.

28
00:01:43,920 --> 00:01:48,570
So we're going to print H which is the second character but it has index of 1.

29
00:01:48,690 --> 00:01:53,820
So then we're going to add two to I which gives us three which is still less than the length of the

30
00:01:53,820 --> 00:01:54,880
string.

31
00:01:54,960 --> 00:01:58,880
So we're going to print out a string of three which is E.

32
00:01:59,340 --> 00:02:04,410
And then we're going to keep repeating this add too which means we're going to printout L and then another

33
00:02:04,410 --> 00:02:05,960
L and then o.

34
00:02:06,360 --> 00:02:13,580
So the end result is that we print every other character and that happens to spell out Hello.

35
00:02:14,040 --> 00:02:17,320
So in the next set of exercises I'm going to have you start writing some four loops
