All right, it's time to have some fun with some arrays so we have a 2D array of zeros or a matrix of
zeros, if you will.
And we want each column to count up a number.
So zero zero zero one one one two two two.
Since this is a debugging exercise, I'm assuming there's something wrong with the code, so let's run
it and see what's wrong.
And it crashes all right now, as always, line by line, we're going to figure out what's causing the
crash as well as the inevitable bugs that come with it.
OK, so I started to zero.
And as the inner loop runs, I increases instead of J.
Well, that's kind of silly.
This is just going to run forever, eventually hitting three.
This array doesn't have an index of three.
So it's Crash's Index at about.
OK, let's fix that.
Run the code.
OK, another crash index, minus one out of bounds, why is that?
OK, I start at zero.
Everything's fine.
But now is negative one.
It doesn't make sense to decrease the counter by one, I don't know why this person would do that.
Let's run the code.
OK, we're close.
Instead of each column counting up a number, each row is counting up a number.
Hmmm, how do we fix that?
Let me trace the runtime.
There should be zero.
All right, I still zero.
And the next zero should go to the index one zero, but instead it's going to go to the index is zero
one because I zero energy is one.
But if we flip them.
Now, the next zero is going to update the index, one zero.
And I believe that should solve everything.
All right, let's rerun the code.
Perfect, every column counts up a number.