Now that you know about both lists and for loops, in this lecture we'll explore how we can use those two things together. Let's go do that now. This is the Visual Studio solution that we set up in the previous lecture. We added our console cards DLL to our project and we have a using directive for the console cards namespace. I should actually create a deck object here rather than just declaring the variable. We'll call the constructor to create a new deck and I'll add a comment above it saying, "Create deck and hand," we'll have a hand of cards. I'll make my hand of cards a list of cards and I'll call it a hand. I'll create a new card list, but I'm getting compilation errors there because it can't find list and that's because the list class is found in system collections generic. In general when you include something like a list or a deck that you know is available somewhere and the compiler complains that it can't find it, the first thing you should check is if you're missing a using directive. Next we'll add some cards to our hand and I can just do that by calling the add method on the list. The way I get the cards is by taking the top card from the deck. It is very unusual if we're playing an actual card game for people to add cards to their hand by creating new cards with a carved printer off to the side, we draw cards from the deck, that's the common way to add cards to a hand. We can just call the deck, take top card method, to actually add a card to the hand. Remember our documentation said, take top card returns the cards to us and we can then just add that card to our hand list because our hand list is a list of cards. Let's do that a few times. Finally we'll get to the for loop part. We'll printed cards in hand. Here's our for loop. Let me Tab and accept that. You can see we have some other suggestions and these are great suggestions too. I'm going to accept all those suggestions. Let's add code to the body of the loop, and all we want to do is print out the card in the hand. I will console.WriteLine and I don't want to say just hand i. We'll actually run that and see what happens but let's talk about how i works first then we'll run it then we'll fix this. The first time through the loop i is set to zero. The first time through the loop this Console.WriteLine will print out the first element in the list at Index 0 because that's the only thing in the body of the loop. After it's done that we'll come back up here and we'll increment i, so i is now one. We'll check to see if i is less than hand.Count, and it is, because handout.Count is three, we have three cards in our hand. One is less than three so we'll come into the body of the loop again and this time i is one, so Console.WriteLine will print out Hand 1. We'll loop again set i to two, two is less than three. We'll come into the body of the loop and Console.WriteLine Hand 2. Then we'll come back again and increment i, so now i is three. Three is not less than three so we'll exit the loop. This less than might have seemed counter-intuitive to you, you might have thought we should do less than or equal to, to make sure we get that last card in the hand but remember we started indexing at zero not at one, so the valid indexes for our hand are 0, 1 and 2. You should also note that I didn't just hard code three here, I actually accessed the count property of my hand list because that way if the size of my hand changes I don't have to try to figure out how to change the hard-coded upper bound for this Boolean expression. I can just dynamically use the correct number based on the contents of the hand. Let me show you why I said that this part is not what we really want to do, because when I run the code just printing out hand, what it tells me is the actual class name. It's the card class, each card in the hand is a card and it gives me the fully qualified names so it's console cards the namespace.card. That's not really what I want, what I want is the rank of the card and I'll concatenate that with the suit of the card. Now if I run again you see I have the king of spades, the queen of spades, and the jack of spades. I didn't shuffle my deck so that I could confirm that I was actually getting the correct cards. Now I manually added cards to the end here one at a time by copying and pasting, but we can certainly use a for loop for that as well. Add five more cards to hand, I'll set i to zero. This time I'm not going to take the suggestion, I'm going to say I want to i less than five and I will increment i each time and I will add. I just tabbed to take those suggestions there, to take five more cards and add them to the hand. I'll put the cards in the hand again. I think I'll add a blank line so we can see where the different prints are separated and when I run my code you'll see I now have eight cards in my hand so the for loop added the 10, 9, 8, 7 and six of spades to my hand and because I used hand.Count here it printed out all the cards in the hand. I do want to point out a few things. First of all, we looked at initializing, and the condition, and modification. We don't have to always initialize to zero. It's most common to initialize to zero but I could also add five cards to the hand by saying i is actually going to start at one. We'll say i is less than or equal to five. Now instead of counting 0, 1, 2, 3, 4, we're counting 1, 2, 3, 4, 5. I'll show you that that still works exactly the same way and as you can see it does. We don't even have to modify just using an increment. I can change this, this is of course still an increment but I can run that code and it does the same thing. I could even add, this would be a mistake but I'll do it anyway. I'll say i equal i plus 10. Of course you should realize if I do that, the first time through the loop i will be one, so I'll take one card but then I'll change i to 11 so this condition will no longer be true so I'll only actually add one card. This is a mistake for this particular problem but I'm just showing you that we can have a different modifier as well. As you can see I only got one more card I got the ten of spades. I'll just change this back to i plus plus. We've added three for loops to this code. This one prints out all the cards in the hand and uses hand.Count in our Boolean expression. This one hard codes the upper bound in our Boolean expression and doesn't set i to zero and doesn't use less than here in our Boolean expression. This one prints the cards in the hand again using hand.Count as our upper bound. That's a best practice to use hand.Count as our upper bound for for loops that we're using to iterate over lists. To recap, in this lecture you learned how to use for loops with lists