Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,300 --> 00:00:05,460
All right, welcome to exercise number for this coach had printed diagonal, but if you run it, it
2
00:00:05,460 --> 00:00:06,840
prints a line of stars.
3
00:00:07,530 --> 00:00:09,720
Whoever wrote this code didn't do a very good job.
4
00:00:10,860 --> 00:00:16,110
Now, at first glance, I'm not entirely sure how we're going to use the counters, A.J., to achieve
5
00:00:16,110 --> 00:00:17,070
the desired output.
6
00:00:17,520 --> 00:00:22,740
So what I'm going to do is use breakpoints to visualize the runtime and hopefully then I can observe
7
00:00:22,740 --> 00:00:23,670
some kind of pattern.
8
00:00:23,940 --> 00:00:25,230
So I'll launch the debugger.
9
00:00:30,590 --> 00:00:31,340
Step through it.
10
00:00:38,340 --> 00:00:43,320
OK, so I know that at this point I need to start a new line to stay consistent with the output, but
11
00:00:43,320 --> 00:00:45,450
this inner loop runs 10 times.
12
00:00:54,670 --> 00:00:59,980
It should only run once during the first pass and twice in the second pass, three times in the third
13
00:00:59,980 --> 00:01:06,640
pass, etc., So the amount of times the inner loop runs depends on the outer loop index, not a static
14
00:01:06,640 --> 00:01:07,410
value of ten.
15
00:01:07,900 --> 00:01:10,600
So we'll put J is smaller than or equal to I.
16
00:01:12,290 --> 00:01:15,500
And after the inner loop runs to completion, will print a new line.
17
00:01:20,620 --> 00:01:21,590
Kate, let's try this out.
18
00:01:27,610 --> 00:01:30,040
And the first pass is going to be a zero.
19
00:01:31,260 --> 00:01:34,240
Jay is going to start at zero as well, so they're going to equal each other.
20
00:01:34,260 --> 00:01:35,700
This condition is going to be true.
21
00:01:38,990 --> 00:01:40,580
The inner loop runs once.
22
00:01:42,220 --> 00:01:45,520
Now, just one, the inner loop breaks, starts a new line.
23
00:01:51,870 --> 00:01:54,750
And now in the second pass, the inner loop is going to run twice.
24
00:01:57,290 --> 00:02:00,470
Until Jay exceeds the outer loop index.
25
00:02:06,630 --> 00:02:09,960
Prince, a new line, and eventually we're going to get our pyramid.
26
00:02:13,580 --> 00:02:14,240
OK, cool.
27
00:02:14,960 --> 00:02:17,210
Now, we don't want a pyramid, we want a diagonal.
28
00:02:17,600 --> 00:02:18,830
So how are we going to do this?
29
00:02:19,920 --> 00:02:23,640
Once again, I'm going to visualize the run time and hopefully I can see some kind of pattern.
30
00:02:27,990 --> 00:02:29,910
OK, so it's fine if this one prince.
31
00:02:37,430 --> 00:02:41,030
In the second pass, I don't want the first loop to print anything.
32
00:02:41,960 --> 00:02:44,330
But we want the second interlude Apprentice star.
33
00:02:49,270 --> 00:02:52,510
In the third pass, I don't want the first loop to print anything.
34
00:02:54,050 --> 00:02:56,090
I don't want the second loop to print anything.
35
00:02:58,110 --> 00:03:00,660
But we want the third in the loop to print star.
36
00:03:07,800 --> 00:03:15,690
Now, I think I see the pattern when the inner loop counter equals the outer loop counter, that's when
37
00:03:15,690 --> 00:03:16,860
we want to print the star.
38
00:03:23,650 --> 00:03:24,880
So let's put our condition.
39
00:03:30,540 --> 00:03:32,340
If Jay is equal to I.
40
00:03:38,360 --> 00:03:39,560
We're going to print the star.
41
00:03:42,190 --> 00:03:43,170
Run the code now.
42
00:03:54,880 --> 00:03:55,810
Wait, what happened?
43
00:03:59,480 --> 00:04:00,740
Let's visualize the runtime.
44
00:04:09,470 --> 00:04:11,120
OK, so here Jake was I.
45
00:04:11,150 --> 00:04:12,200
So it should print.
46
00:04:22,580 --> 00:04:26,030
In the second pass, when Jay, smaller than I, nothing happens.
47
00:04:27,820 --> 00:04:30,220
But when the indices are equal, it prints star.
48
00:04:32,080 --> 00:04:38,770
I see, even though we can't print a Starwind Jay less than I, we still need to provide the empty space
49
00:04:38,770 --> 00:04:40,110
needed to print the pyramid.
50
00:04:40,750 --> 00:04:42,520
So we're going to add an statement.
51
00:04:42,550 --> 00:04:44,680
Otherwise, when J is less than I.
52
00:04:45,710 --> 00:04:47,360
We're going to print three spaces.
53
00:04:52,430 --> 00:04:53,960
All right, let's see how this would look.
54
00:05:04,120 --> 00:05:06,730
OK, so here Jay is equal to I, so we should print.
55
00:05:15,540 --> 00:05:19,290
And the second pass, when Jay smarter than I print an empty space.
56
00:05:23,250 --> 00:05:25,440
But when the indices are equal, it prints a star.
57
00:05:29,840 --> 00:05:32,720
Now, the inner breaks moving on to the third pass.
58
00:05:36,170 --> 00:05:41,210
I to zero prints and empty space, another empty space.
59
00:05:42,970 --> 00:05:48,220
Princess Star, and if you keep going, eventually you're going to achieve a very nice diagonal.
60
00:05:49,640 --> 00:05:51,710
As expected, it works beautifully.
61
00:05:52,060 --> 00:05:54,370
We just debugged exercise number for.
5323
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.