All right. Before we get started, I have to admit variables can be hard for kids because they feel very mathy. In a way they actually are mathy, right? Because we're going to be dealing with sequences of numbers. But, it's also, I feel with repeat. One of these things where we teach these logicing it out or just if you just pay attention and we'll keep track of what the code is doing, you can feel like you can actually have power over the computer. So, well, it's a challenge. I feel when students have a technique to trace and keep track and analyze the code we're looking at in these particular examples, they really turn up turning point and they start to say, hey this is me I can do amazing things. All right, let's remind you of the first question because there were lots of different ones and they all looked really similar. So, setting count to eight repeating ten times. Yeah, that's a tricky one. I think it's always good to switch things up with kids sometimes and have a none of the above or something isn't right or something like that. Then this is a fairly normal structure we're having whatever we're having things to do in this case saying things come before we change our variable. Some kids a little bit upset you said countdown versus say and I'm like well, what's the point of saying something? Et cetera. So, why is it nothing above? Why isn't it maybe ten down to one or eight down to something? Well, the key thing here is first off we're going to say it's crucial to do something we describe in English. So, that's my countdown point. The other thing is that we really want kids to be able to trace code crossing out the values of the variables while at the same time recording the output. So, let's look at a this will be a little long but it's again it's rigorous process that once you get in the swing of it it looks it gives you power. All right. So, there's basically one variable we have to keep track of count. I like to draw my variables in a table albeit. We don't know how many rows are going to be in our table in advance. But, on the other hand if you're doing it on the board and let me tell you this is far easier to do on a chalkboard. Then what I do is I just separate out the side where we're keeping track of the variables with what we're keeping track of the output, okay? With a line or something. Just because they don't necessarily they're not going to match up in terms of space, okay? So, we're going to go a bit at a time. We start before we even start the loop. We set the variable account equal to eight. So now, count has eight. The next thing that happens is we start loop repeat ten times, say count. All right that's my output over there, I just set the number, eight. I looked I found that out because I looked over to my count variable and I looked it up. All right. Now, we're on to the next instruction count, change count by negative one. All right. Here is the key thing. Again a variable is a placeholder, it can only hold one value at a time. So, count is there and I thought I'd cross out what was on there, which is eight and replace it with a seven. If you had an envelope, you take the piece of paper out you cross out the eight and you write a seven. Because it's really about your you're literally copying over the bits. Honestly, that the variable uses to represent whatever is in the variable count. All right. So now, we've just by the way finished the first loop and we'll come back to that later because it probably is going to be useful to keep track of that. I go back up and repeat the next thing that happens is I say whatever's in count wasn't seven. So now, I outputted seven over on the right. Now, I'm going to the next instruction change count by negative one. So, I'm going to cross out seven and have six in my count placeholder, right? Now, I'm done with that bottom loop. I'm going to go back up to the repeat and the first thing I do is say something. So, I'm going to say whatever values and kick six, or count at six there is. Then I'm going to change count by negative one. So, cross out the six bring in the five. Let's see I think it will go all well. Let's go up to the repeat. Then I'm going to say five and already I'm just going to say. So, it's going to be important to keep track of the iteration, because as you've noticed, we say a value but then we change it in that same iteration. So, at the end of any given iteration of these loops, what we've said and what we've got in our variable are different. So, to keep track of that, I sometimes keep iteration and I keep track of where I'm changing my count variable. So, I set it to eight before we even started the loop. I set it to seven by the end of the first loop. So, I usually keep track of the iteration at the end of that iteration. I changed it to six at the end of the second loop or it is the value six at the end of the second loop, it is the value five at the end of the third loop. Because as you can see if we could keep going but it will be hard to keep track of, which loop iteration? How many times have we repeated already? So, at this point we have repeated three times. But actually my output reflects the beginning of the fourth iteration by the way. Because you only say things inside the loop. So, since I have four things that have been said, that output reflects a fourth part. All right. So, we're halfway through the fourth loop. Let's just jump ahead, okay? I'll tell you about this before but here we're going to be down all the way we've done all the way to the very end. How can I tell we've done to then? Two things, one my iteration count it goes down to ten. Also I can look at my output and I count how many things I've said 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, 10 fingers you we're gonna find out are really good, okay. So, I've said seven things I there should be 10 says and also my changing of my count variable I have that recorded down 10 times. All right. This is, yeah, this is mentally a little challenging. But, so what are big teacher takeaways? Well, the question you will probably ask and hopefully your students will ask is, why isn't that negative two value for count? Why isn't that ever said out in my output? Here's the answer. The answer is because even after we say that last value negative one, we actually go ahead and change count one more time. Then we're like oh, now we're done repeating 10 times. So, nothing else happens. So, whenever you change a variable value after your last evidence of what that variable value is counted in this case, then yeah you're going to end up like that. It may seem picky because we're never actually print it out but it's again in this idea of being able to accurately and very rigorously keep track of what each variable is and what our output is. This is a good thing to be reinforcing with students. All right, couple of the things. Teacher tip, two smaller numbers do not chose eight and 10 because you'll get lost and it takes forever and it gets a little two, three and five. It'd be better to do more things with smaller numbers, okay? So, take it from me, don't do it. Let's go onto the next one. What best describes what this code will do? So, take a minute to look over. Hopefully, there's something you noticed. Which is that you need to pay attention to detail. We've heard this before there's actually two change instructions which may or may not be true maybe this is more of a debugging question. I mean, it would be, okay. B obviously would be silly to write this code this way. But, this will happen to students when they start using variables inside repeats. They'll forget where they did it especially if they're doing a lot of things in there and they may do it more than once. So, in fact, just to follow-through. We say count to one and we repeat five times we change count by one. So now, it's two and then we say the number two and then we immediately reduce it by one. So now, it's back down one. We go back up again, we increase it by one is two. We say two. So, five different times we basically increases from one to two say the number two and then decrease it from two to one. So that, each time we come up to loop it's starting at one again. How about this one? The difference here just as a point out in the answer options is instead of saying what was said. I'm actually saying will be the value in the variables after the code runs. This is good because usually are say is in the loop. This is actually getting them to think about when the code is completely over, what will be the value of the variables. This is a very, very common technique to use in testing of computer science when we're doing multiple choice and paper and pencil type-test. So, it's really, really important for students to be able to do this. It's really asking the same thing, it's just it's a little bit different. All right. So, the answer is zero and six. What's going on? Well, we have two variables here and keeping track to two variables is more challenging than keeping track of one. We can use the exact same table method to get there by the way. The key thing here is that other count we set it to five and we noted that we're changing it by negative one. So, that's it, it's going down. If we want to keep track of how many times by the way five, four, three, well so the first time it's five and then I subtract one it'll be four. So, the end of just one loop it would be four. The end of two loops that would be three, two, one, zero, okay? So, at the end of the entire code. Because I would have reduced it by four and fall the generation three, two, one, zero. It's going to be zero. But, for count it starts at one. Is counting up, okay? By the end of the second loop or the end of the first loop it's not going to be one. It started at one, now it's going to be two at the end of the first loop. Three, four, five, six, all right. So, what's our takeaway? Reporting after the entire program not in the loop is another good way to get kids thinking. It shows this issue of, if you start at zero and you repeat n times you'll go up to n. Or if you started n you'll be n times you get down to zero or if you're counting down. But, if you start at one, and you repeat n times, you'll end up at n plus one. So, we started at one and we ended up at six. That's just a really common structure and that's actually common in huge amounts of computer science. Students will software engineers at Google have errors with regard to this every day. But, you've also shown a very key concept which is computers are very precise and humans are not. Don't try to do it in your head, count on your fingers. Finger counting is very, very important with loops. People say, well how do I count if it's a 100? Well, you count a few at the beginning to get the concept and figure out what your pattern is and then you count a couple of the end, that's pretty hard for kids at this point in time. All right. Last one, what best describes what this code will do. So, what was the thing that you notice that was different? You can just pick a color, put a color that's different in this code. Green, prisoners color? Yeah, those are operations. So, instead of printing out the actual count value we're printing out 10 minus the count value. So, this actually happens reasonably often in computer science it's not crazy to ask for this, but that's why it looks like we're counting down causes start at 10 and we change the count by negative one. So, it rends going 10, 9, 8, 7, 6, that's what count is doing. But since we're doing 10 minus count, that will actually then make it go up. In fact, so we start off 10 minus 10 is zero. So, we're going to start at zero. Then we can think of what count will be as we enter the 10th iteration. So, it'll be 1 and 10 minus 1 is 9. So, we're going to go from zero to nine. So again, you might do some tracing tables with the kids with these. But the key thing here is sometimes we can use our counter to calculate something else. I have to keep two variables. But generally you could keep two variables two. But this is a nice challenge problem for students who really like getting into the logic of it dealing with math and why not.