1 00:00:00,210 --> 00:00:03,810 Before we start, did you try solving the workbook yourself? 2 00:00:03,840 --> 00:00:09,650 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,820 --> 00:00:17,090 Welcome to Work Book 4.1 In this workbook, we need to print this passage six times, but we don't want 4 00:00:17,090 --> 00:00:18,500 to copy and paste code. 5 00:00:18,500 --> 00:00:21,320 Instead, what we want to do is create a function. 6 00:00:21,320 --> 00:00:27,230 As always, it's going to be public and for us to be able to access it from the static main function, 7 00:00:27,890 --> 00:00:30,620 our print lines function needs to be static as well. 8 00:00:30,620 --> 00:00:32,990 Don't worry too much about what static is right now. 9 00:00:32,990 --> 00:00:34,910 We will cover it in module two. 10 00:00:34,910 --> 00:00:35,810 Anyways. 11 00:00:35,810 --> 00:00:37,580 The function is going to be void. 12 00:00:37,580 --> 00:00:39,860 It's not going to return any values. 13 00:00:39,860 --> 00:00:46,310 We're going to talk about return values later in the section and the function name is print lines. 14 00:00:46,790 --> 00:00:49,370 The function will not receive any parameters. 15 00:00:49,370 --> 00:00:52,760 We will talk about parameters again later in the section. 16 00:00:53,710 --> 00:01:00,790 And all this function is going to do is print four lines, print these four lines whenever it's called. 17 00:01:01,390 --> 00:01:06,820 And that is all, Let me fix up the indentation and we are good. 18 00:01:07,210 --> 00:01:08,680 Now I know what you're thinking. 19 00:01:08,680 --> 00:01:09,760 What is void? 20 00:01:09,760 --> 00:01:10,950 What are parameters? 21 00:01:10,960 --> 00:01:12,910 Don't worry about this right now. 22 00:01:12,940 --> 00:01:14,520 All in due time. 23 00:01:14,530 --> 00:01:20,380 All you need to know is that when we call print lines, it's going to perform the task of printing these 24 00:01:20,380 --> 00:01:21,010 lines. 25 00:01:21,010 --> 00:01:22,900 So let's do just that. 26 00:01:22,930 --> 00:01:25,780 Task two is to call the function six times. 27 00:01:25,780 --> 00:01:31,540 So we'll call this six times one, two, three, four, five, six. 28 00:01:31,540 --> 00:01:38,200 And by the way, I know that I laid out all of your tasks in the code itself, but those instructions 29 00:01:38,200 --> 00:01:39,700 do not replace the ones. 30 00:01:39,700 --> 00:01:40,720 I'll learn the part. 31 00:01:40,720 --> 00:01:44,350 The instructions on learn the part are much more detailed. 32 00:01:44,380 --> 00:01:45,190 All right. 33 00:01:45,190 --> 00:01:51,040 Anyways, let us go ahead and visualize the runtime using our debugger. 34 00:01:51,810 --> 00:01:53,610 Putting breakpoints everywhere. 35 00:01:54,860 --> 00:01:59,390 So here what we can do is step inside the function by pressing step into. 36 00:01:59,630 --> 00:02:04,310 And once you're inside the function, you can just keep pressing step over. 37 00:02:04,340 --> 00:02:08,940 You don't want to press step into again because then it's going to step into print line. 38 00:02:08,960 --> 00:02:10,300 Let's do just that. 39 00:02:10,310 --> 00:02:12,920 And it steps inside the print line function. 40 00:02:12,950 --> 00:02:17,270 Oh, yes, Print line is also a function, but we're not going to get into that right now. 41 00:02:17,300 --> 00:02:19,040 Let us restart the runtime. 42 00:02:19,640 --> 00:02:23,480 All we want to do is step inside the function that we created. 43 00:02:23,480 --> 00:02:25,220 We will step inside the function. 44 00:02:25,220 --> 00:02:31,160 And once you're inside the function that you called, you can just step over all of the lines in order 45 00:02:31,160 --> 00:02:34,210 to execute them without diving into their internals. 46 00:02:34,220 --> 00:02:36,500 So we'll step over this line printing. 47 00:02:36,500 --> 00:02:42,450 I will not copy and paste code, stepping over this line, stepping over that and beautiful. 48 00:02:42,470 --> 00:02:48,050 Now, we'll continue to the next breakpoint and once again, we step inside the function and take this 49 00:02:48,050 --> 00:02:49,200 as a rule of thumb. 50 00:02:49,220 --> 00:02:55,160 Once you're already inside the function that you're calling, then you can just keep pressing step over 51 00:02:55,160 --> 00:02:58,340 to execute every line inside of this function. 52 00:02:59,240 --> 00:03:00,400 All right. 53 00:03:00,410 --> 00:03:04,520 Repeating that stepping inside of our third function call. 54 00:03:05,520 --> 00:03:06,180 It prints. 55 00:03:06,180 --> 00:03:13,260 I will not copy and paste code again, prints all of these messages and it's going to do that three 56 00:03:13,260 --> 00:03:14,380 more times. 57 00:03:14,400 --> 00:03:17,610 I'm not going to step inside the function every single time we call it. 58 00:03:17,610 --> 00:03:24,390 So what I'll do actually is I will remove the breakpoints, press, continue to resume execution, and 59 00:03:24,390 --> 00:03:32,280 here you will see that by virtue of calling the function six times, our message was printed six times. 60 00:03:32,280 --> 00:03:34,260 That is all for workbook 4.1. 61 00:03:34,260 --> 00:03:36,750 I hope you enjoyed this breakpoint session.