1 00:00:00,920 --> 00:00:02,810 All right, exercise number five. 2 00:00:05,180 --> 00:00:09,920 If we look at the output, it seems like we want to get some kind of pyramid that skips every second 3 00:00:09,920 --> 00:00:12,470 row and prints the letter that follows. 4 00:00:12,920 --> 00:00:16,490 Let's hope the code that we have print anything remotely similar. 5 00:00:23,880 --> 00:00:25,260 And what the heck is this? 6 00:00:25,710 --> 00:00:27,740 We definitely have our work cut out for us. 7 00:00:27,780 --> 00:00:29,130 OK, where do we start? 8 00:00:29,640 --> 00:00:30,270 You know what? 9 00:00:30,300 --> 00:00:31,220 I have no idea. 10 00:00:31,230 --> 00:00:36,570 So I'm going to do is just place a bunch of break points and just try to see why this code is behaving 11 00:00:36,570 --> 00:00:37,530 the way that it is. 12 00:00:45,330 --> 00:00:51,720 OK, so the first part of the outer loop is one, I imagine this two is not zero skipping the statement 13 00:00:52,260 --> 00:00:57,540 and as soon as we enter the inner loop, A gets converted to another letter before it has the chance 14 00:00:57,540 --> 00:00:58,440 to get printed. 15 00:01:03,600 --> 00:01:04,569 That's not right. 16 00:01:04,590 --> 00:01:07,130 If you look at the output, we need to print the letter A.. 17 00:01:07,770 --> 00:01:11,010 So what I'm going to do is start by moving this after the print function. 18 00:01:15,660 --> 00:01:16,790 All right, let's try again. 19 00:01:24,430 --> 00:01:30,490 OK, just not smaller than I, so it prints the letter A, OK, and now if I look back at the output, 20 00:01:30,490 --> 00:01:35,650 I need to start a new line, but this inner loop is going to run ten times before the next new line, 21 00:01:36,130 --> 00:01:37,520 which is not what we want to do. 22 00:01:37,930 --> 00:01:42,950 So right there, by visualizing the runtime using breakpoints, I've already identified the second bug. 23 00:01:43,600 --> 00:01:49,300 So once again, the amount of times the inner loop runs depends on the outer loop index, not a static 24 00:01:49,300 --> 00:01:50,100 value of ten. 25 00:01:50,380 --> 00:01:51,610 So we'll change that. 26 00:01:52,180 --> 00:01:54,760 And OK, I think we might be on to something. 27 00:01:54,760 --> 00:01:55,630 Let's run the code. 28 00:02:10,110 --> 00:02:14,430 Hmm, it's skipping a whole lot of letters that can't be good. 29 00:02:21,620 --> 00:02:23,090 Let's relaunch the debugger. 30 00:02:40,340 --> 00:02:41,780 OK, we're fine here. 31 00:02:46,650 --> 00:02:50,040 So at this point, I equals two and it's about to set this run. 32 00:02:54,100 --> 00:02:54,940 Equals three. 33 00:03:04,560 --> 00:03:09,120 Oh, I see every time it prints an empty space, it also increments the letter. 34 00:03:25,160 --> 00:03:28,340 So this line should be in the outer loop, not the inner loop. 35 00:03:32,230 --> 00:03:33,910 All right, restart the debugger. 36 00:03:43,630 --> 00:03:44,710 Prince, the letter A. 37 00:03:48,140 --> 00:03:49,400 Skips the next one. 38 00:03:59,950 --> 00:04:01,050 And that's all. 39 00:04:04,750 --> 00:04:07,550 Good job on debugging, exercise number five. 40 00:04:08,110 --> 00:04:11,770 This was definitely not an easy one to debug, but we made it.