1
00:00:01,010 --> 00:00:02,780
Welcome to exercise number six.

2
00:00:03,920 --> 00:00:08,450
In this exercise, the output we're expecting is a right diagonal and hopefully our code can print something

3
00:00:08,450 --> 00:00:09,380
remotely similar.

4
00:00:15,170 --> 00:00:19,310
And you know what, that's not a bad start, at least compared to the last one, we have something to

5
00:00:19,310 --> 00:00:22,910
work with, but like always, let's put some break points and visualize the run time.

6
00:00:22,910 --> 00:00:24,890
Hopefully we can identify the first bug.

7
00:00:32,400 --> 00:00:35,850
OK, so I as one is also one Apprentice star.

8
00:00:38,750 --> 00:00:44,750
And there's the first bug, the first line prints many spaces with a start at the end, the second line

9
00:00:44,750 --> 00:00:51,050
prints one less that amount a third line prints one, lets that amount onto the last line, prints only

10
00:00:51,050 --> 00:00:51,530
the star.

11
00:00:51,950 --> 00:00:56,600
And going back to our code, the amount of times the inner loop runs goes up with the outer loop counter.

12
00:00:57,180 --> 00:00:59,660
Instead, it needs to go down with the outer loop counter.

13
00:01:00,700 --> 00:01:03,010
So I should start by equaling five.

14
00:01:08,780 --> 00:01:13,310
And the outer loop is going to keep running as long as I is bigger than or equal to one.

15
00:01:20,470 --> 00:01:22,840
And we're going to decrease the counter after every run.

16
00:01:26,270 --> 00:01:27,980
OK, relaunching the debugger.

17
00:01:30,820 --> 00:01:31,990
I starts at five.

18
00:01:40,720 --> 00:01:42,730
So the inner loop runs five times.

19
00:01:48,630 --> 00:01:55,760
Until Jay exceeds five, breaking the inner loop prints a new line and the second pass equals four,

20
00:01:55,770 --> 00:01:58,890
so the inner loop is going to run four times and this is perfect.

21
00:01:58,900 --> 00:02:00,180
We're making progress.

22
00:02:07,910 --> 00:02:08,320
OK.

23
00:02:11,250 --> 00:02:14,160
Now, the next thing we want to do is only print the final star.

24
00:02:18,760 --> 00:02:19,840
And how are we going to do that?

25
00:02:20,380 --> 00:02:22,840
Let's find out, relaunched the debugger.

26
00:02:29,020 --> 00:02:33,800
First pass equals five JS one, we don't want to print anything here.

27
00:02:33,940 --> 00:02:36,570
Nothing here, nothing here.

28
00:02:37,860 --> 00:02:42,780
We only want to print the star at the very last run one J equals a five.

29
00:02:45,870 --> 00:02:50,990
Second pass equals four, once again, we don't want to print any stars, not until J.

30
00:02:51,000 --> 00:02:52,230
Equals IV for.

31
00:02:56,010 --> 00:02:59,820
So when Jay is less than I, we want to print two empty spaces.

32
00:03:09,130 --> 00:03:10,930
Otherwise, we want to print the star.

33
00:03:18,210 --> 00:03:19,200
All right, last time.

34
00:03:23,620 --> 00:03:28,450
First, past equals five days less than that, so it going to print the white space.

35
00:03:35,340 --> 00:03:38,520
And it's going to keep printing white space until I equals Jay.

36
00:03:45,890 --> 00:03:50,990
Second pass equals four J once again is less than ISO, it's going to print space.

37
00:03:53,200 --> 00:03:55,150
Until Jake equals eye for.

38
00:03:59,320 --> 00:04:04,930
Third pass equals three white space, white space, and where J equals three, it prints a star.

39
00:04:05,260 --> 00:04:07,390
And just like that, we debugged our code.

40
00:04:08,960 --> 00:04:11,960
And it should print a nice right diagonal perfect.

41
00:04:17,709 --> 00:04:20,470
Now you can feel free to run the code to your heart's content.

