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 Workbook 6.7 an array stores Java's fight record apparently, and we have to use a for loop
to count the number of wins and update this variable.
And I'm assuming using the same for loop count the number of losses and update the loss is variable.
So we can do is create a for loop.
Where I starts at zero, the for loop is going to keep running so long as I is smaller than the length
of the array.
And every time the for loop runs we increase by one.
And inside the for loop, we can index through every single element of the record array.
And if that element happens to equal when.
Then we're going to increase the number of wins by one.
Otherwise, the only other possible value it could be is loss.
So we'll say else.
Losses plus plus.
And now here we can just replace wins by the actual variable.
Doing the same thing here.
That's really it.
Now we can visualize the runtime.
I'll put a breakpoint right here.
All right, So our variables start off equaling zero zero wins, zero losses during the first two run
of our loop I equals zero.
The element at index zero is a win.
So this evaluates to true and we update our wins variable by one.
Perfect.
Now I equals one.
That's also a win.
I equals two is also going to be a win.
So let's step through those.
All right, now we've got three wins.
I equals three.
The element that index three is a loss.
So now the WL statement is going to get called increasing losses by one.
When I equals four, the element is a win.
I equals five is also a win.
The element that index six is a loss, increasing losses by one and now I a plus plus is going to increase
I to seven seven is not smaller than the length of our array which is seven.
So the four loop breaks.
With a professional record of five wins and two losses.
Java Fury.
All right.
There we go.