This is where we can actually get into our bread and butter with 2D arrays. We need to be able to loop over them. In the same way with a 1D array, we needed a single loop. With a 2D array, we're going to need two loops and they're going to be nested inside each other. So if students were struggling with nested loops before, this will be a great place to review. There will be something a little more visual they can hang their hats on in terms of doing this. 8.2.1 is a one-liner, 8.2.2 is quick and easy. There's a lot into 8.2.3 and I've got a number of additional recommendations for you, the teacher to modify the activities to there to a greater benefit and some tips as well. So giving the numbers of rows and columns we actually mentioned in the last one. I guess it's just important to revisit, but remember my short gives you the rows and the longer gives you the columns. That's important, the key there actually pointing out here, which I mentioned in the last video, is that because we're not allowing ragged arrays, we are having all rectangular, not necessarily square but rectangular size arrays. You can always just take it into a sub-zero dot length, that is the arraying sub-zero. You don't have to think about which row you're asking the length of. All the rows have the same length. So you might as well grab the zero as well. So again, this is something you can just have your kids memorize and that's okay. Couple of good questions here that are again just pushing on the issue of we start indexing at zero, and then we get into our bread and butter. So you've got word walls, something up there. This is what you want. Your kids should just be able to write that out without thinking about it. I told my students there's no memorization in programming, there isn't, but there are things that you do so frequently that it just behooves you to, it's called chunking, and your brain actually becomes a chunk. You don't have to think about the individual letters or what am I choosing for my iterator name or is it less than or less than equal to? When we're talking 2D arrays, it's int row equals zero, where less than array dot length row plus plus and col equals zero. Col less than array zero dot length col plus-plus. You just need to make sure that array is actually the name of the variable that you're using but everything else you have control over when you're writing code, col it row, call it column, do it, also use arrays of zero dialing. There's next an activity where this shows it off doing get average, which is if you remember, it's a gather, right? I thought I had gather around there somewhere, but anyway, this is a gather, right? It's a very simple gather. We've got our row and our column just like we had above. It's the same. So again, you could have them write that out like in the beginning of every period for a week and or longer is fine. But like dots, you can write that and get points on the free response question. Here's my gather, right? What happens inside the loop is a gather. They chose to break this up across two rows, I think, to explicitly show getting the value from the array a in this case, I'm not col array a, row column into a variable called value. You could of course, do this all on one line, right? But this is a simple sum, we're gathering the total and at the end we're going to divide it. But how many things are we taking the average of? It's not just a dot length, that's just the how many rows you've got, right? It's the total number of elements. Go back and draw the rectangle so that's going to be the total number of times each of the loops rounds. So it's really easy, whenever your loop iterators end with a dot length and a to zero dot length, multiply those together, that's how many things you went out across. If that's blowing student's mind. Well, first off, I'm going to have some print stuff that will do with that. But they could set up another iterator account into count equal zero and every time it goes through the loop, they can increment count and divided by count and that would be sure they had the right number as well. The way they have students then interact with that activity. So they give them all the code that does the average. They say, "Hey, add a row and check that the average still comes out." I think that's not very helpful in really reinforcing how the nested loops work. Here's my recommendation instead. I think you should have them add a print statement in the loop showing index values. Now you could leave it open-ended for them or you could tell them how you want that print statement to look. But it's really, really value so that you can see I'm getting ready to add zero sub-zero. I'm getting ready to add zero one, all that stuff. Here's what I came up with. I said right at the beginning of the loop, adding element at index and then you got to do some kind of fun, funky stuff with your print, getting your spacing correct and whatever but open-bracket without a space after it, quote and then print out the row index plus quote space, comma space quote plus col plus quote, open bracket space and I used a print there. So I want to get all of my items, they're on the same row. I'm going to print those at all on the same row in my print out. You may or may not want to do that, but then I didn't put a print line after the inner loop was done to indicate I was going down to the next one. You could also have them say row zero and they're doing that column zero, there's a lot of ways you could do it, but just whatever way you think would make it clear and that's how the output would look if he did it my way. Finally, right after this, and I don't know if this is something we're going to start seeing more often or what caused this to come about, but I think this is really cool. There's an actual debrief about the code, about things you should be noticing about the code. So I think this is a really good thing to do and maybe you won't even come up with code deeper is for other activities. Whereas the kids be like, what should be in our code debrief? What are things we should be noticing about this code? Finally, we've got, I think we've even got more than one movies. There's a mix-up code problem, that's our most wanted problem. There's nothing super special about it. I went through and did it to make sure there are no tricks. Again, the key thing we want to remind students, and this is really going to help them now with the nested loops, work outside in. Okay? Where now what we know is not just to we have our method on the outside, but then our outer loop is going to be row and our inner loop is going to be columns and if they do that, that's going to make this really easy and I think reinforce the structure we want them to see here, rows then columns. There's one more activity and I don't actually really like it as it is. Well, it's column major traversal, I told you we'd never really, we rarely loop over things in column major and I think I wouldn't even emphasize the fact that it's column major, I just say alternate traversal like can you print it in other ways? But I think just having kids run the code like there's just going to be like. I would instead, this basically says like instead of printing out all the things across the row, can you go down the columns like that? Yes, you can. You just put the columns on the outside, it's always tricky. I would have do this in real persons, like have some kids stand or sit as an array [inaudible] in array and keep track of row and column on the board but seeing rows and columns of people standing or sitting is way more helpful in understanding what order are we wanting. Now how can we set up our loops so that that happens? So I would just like blank the screens at this point, don't let them look at that and then line the kids up in chairs or whatever. Send somebody the board and have them keep track of row and column and then be like, let's write the code, so that we go through the kids in this order down the columns of them as being seated.