1 00:00:00,180 --> 00:00:03,870 Before we start, did you try solving the workbook yourself? 2 00:00:03,900 --> 00:00:09,660 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,980 --> 00:00:18,870 Welcome to Workbook 6.7 an array stores Java's fight record apparently, and we have to use a for loop 4 00:00:18,870 --> 00:00:21,570 to count the number of wins and update this variable. 5 00:00:21,570 --> 00:00:27,510 And I'm assuming using the same for loop count the number of losses and update the loss is variable. 6 00:00:27,510 --> 00:00:30,870 So we can do is create a for loop. 7 00:00:30,870 --> 00:00:36,780 Where I starts at zero, the for loop is going to keep running so long as I is smaller than the length 8 00:00:36,780 --> 00:00:37,650 of the array. 9 00:00:38,280 --> 00:00:41,790 And every time the for loop runs we increase by one. 10 00:00:42,740 --> 00:00:48,240 And inside the for loop, we can index through every single element of the record array. 11 00:00:48,260 --> 00:00:53,420 And if that element happens to equal when. 12 00:00:55,040 --> 00:00:58,160 Then we're going to increase the number of wins by one. 13 00:00:59,950 --> 00:01:04,000 Otherwise, the only other possible value it could be is loss. 14 00:01:04,000 --> 00:01:05,260 So we'll say else. 15 00:01:06,280 --> 00:01:08,290 Losses plus plus. 16 00:01:09,910 --> 00:01:14,920 And now here we can just replace wins by the actual variable. 17 00:01:19,660 --> 00:01:21,220 Doing the same thing here. 18 00:01:26,880 --> 00:01:27,930 That's really it. 19 00:01:27,960 --> 00:01:30,100 Now we can visualize the runtime. 20 00:01:30,120 --> 00:01:32,190 I'll put a breakpoint right here. 21 00:01:38,270 --> 00:01:45,200 All right, So our variables start off equaling zero zero wins, zero losses during the first two run 22 00:01:45,200 --> 00:01:47,870 of our loop I equals zero. 23 00:01:47,900 --> 00:01:50,540 The element at index zero is a win. 24 00:01:50,540 --> 00:01:55,460 So this evaluates to true and we update our wins variable by one. 25 00:01:55,820 --> 00:01:56,750 Perfect. 26 00:01:58,580 --> 00:02:00,100 Now I equals one. 27 00:02:00,110 --> 00:02:01,400 That's also a win. 28 00:02:01,400 --> 00:02:03,500 I equals two is also going to be a win. 29 00:02:04,280 --> 00:02:05,690 So let's step through those. 30 00:02:07,720 --> 00:02:09,610 All right, now we've got three wins. 31 00:02:11,110 --> 00:02:12,280 I equals three. 32 00:02:12,280 --> 00:02:14,320 The element that index three is a loss. 33 00:02:14,320 --> 00:02:19,030 So now the WL statement is going to get called increasing losses by one. 34 00:02:20,780 --> 00:02:23,750 When I equals four, the element is a win. 35 00:02:27,230 --> 00:02:29,600 I equals five is also a win. 36 00:02:33,560 --> 00:02:40,580 The element that index six is a loss, increasing losses by one and now I a plus plus is going to increase 37 00:02:40,580 --> 00:02:45,230 I to seven seven is not smaller than the length of our array which is seven. 38 00:02:45,920 --> 00:02:47,630 So the four loop breaks. 39 00:02:48,560 --> 00:02:53,090 With a professional record of five wins and two losses. 40 00:02:53,870 --> 00:02:54,930 Java Fury. 41 00:02:54,950 --> 00:02:55,970 All right. 42 00:02:55,970 --> 00:02:56,780 There we go.