Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
Welcome to Work Book 4.1 In this workbook, we need to print this passage six times, but we don't want
to copy and paste code.
Instead, what we want to do is create a function.
As always, it's going to be public and for us to be able to access it from the static main function,
our print lines function needs to be static as well.
Don't worry too much about what static is right now.
We will cover it in module two.
Anyways.
The function is going to be void.
It's not going to return any values.
We're going to talk about return values later in the section and the function name is print lines.
The function will not receive any parameters.
We will talk about parameters again later in the section.
And all this function is going to do is print four lines, print these four lines whenever it's called.
And that is all, Let me fix up the indentation and we are good.
Now I know what you're thinking.
What is void?
What are parameters?
Don't worry about this right now.
All in due time.
All you need to know is that when we call print lines, it's going to perform the task of printing these
lines.
So let's do just that.
Task two is to call the function six times.
So we'll call this six times one, two, three, four, five, six.
And by the way, I know that I laid out all of your tasks in the code itself, but those instructions
do not replace the ones.
I'll learn the part.
The instructions on learn the part are much more detailed.
All right.
Anyways, let us go ahead and visualize the runtime using our debugger.
Putting breakpoints everywhere.
So here what we can do is step inside the function by pressing step into.
And once you're inside the function, you can just keep pressing step over.
You don't want to press step into again because then it's going to step into print line.
Let's do just that.
And it steps inside the print line function.
Oh, yes, Print line is also a function, but we're not going to get into that right now.
Let us restart the runtime.
All we want to do is step inside the function that we created.
We will step inside the function.
And once you're inside the function that you called, you can just step over all of the lines in order
to execute them without diving into their internals.
So we'll step over this line printing.
I will not copy and paste code, stepping over this line, stepping over that and beautiful.
Now, we'll continue to the next breakpoint and once again, we step inside the function and take this
as a rule of thumb.
Once you're already inside the function that you're calling, then you can just keep pressing step over
to execute every line inside of this function.
All right.
Repeating that stepping inside of our third function call.
It prints.
I will not copy and paste code again, prints all of these messages and it's going to do that three
more times.
I'm not going to step inside the function every single time we call it.
So what I'll do actually is I will remove the breakpoints, press, continue to resume execution, and
here you will see that by virtue of calling the function six times, our message was printed six times.
That is all for workbook 4.1.
I hope you enjoyed this breakpoint session.