Welcome to exercise number six.
In this exercise, the output we're expecting is a right diagonal and hopefully our code can print something
remotely similar.
And you know what, that's not a bad start, at least compared to the last one, we have something to
work with, but like always, let's put some break points and visualize the run time.
Hopefully we can identify the first bug.
OK, so I as one is also one Apprentice star.
And there's the first bug, the first line prints many spaces with a start at the end, the second line
prints one less that amount a third line prints one, lets that amount onto the last line, prints only
the star.
And going back to our code, the amount of times the inner loop runs goes up with the outer loop counter.
Instead, it needs to go down with the outer loop counter.
So I should start by equaling five.
And the outer loop is going to keep running as long as I is bigger than or equal to one.
And we're going to decrease the counter after every run.
OK, relaunching the debugger.
I starts at five.
So the inner loop runs five times.
Until Jay exceeds five, breaking the inner loop prints a new line and the second pass equals four,
so the inner loop is going to run four times and this is perfect.
We're making progress.
OK.
Now, the next thing we want to do is only print the final star.
And how are we going to do that?
Let's find out, relaunched the debugger.
First pass equals five JS one, we don't want to print anything here.
Nothing here, nothing here.
We only want to print the star at the very last run one J equals a five.
Second pass equals four, once again, we don't want to print any stars, not until J.
Equals IV for.
So when Jay is less than I, we want to print two empty spaces.
Otherwise, we want to print the star.
All right, last time.
First, past equals five days less than that, so it going to print the white space.
And it's going to keep printing white space until I equals Jay.
Second pass equals four J once again is less than ISO, it's going to print space.
Until Jake equals eye for.
Third pass equals three white space, white space, and where J equals three, it prints a star.
And just like that, we debugged our code.
And it should print a nice right diagonal perfect.
Now you can feel free to run the code to your heart's content.