Petting Kittens

Today we were asked to find a fun way to represent the each method. This method loops over an array and does something to each item in the array. There are so many ways this can be shown, but I figured what way is better than with kittens? (Sadly I am not currently a kitten owner. If I were, have faith that they would have made a guest appearance in this post!)

So, we start with a family of kitties. This is our array.kitty.each1

Aren’t they so cute?
They’re so cute, let’s name them.


Oh, but who is that? It’s Mr. Each! Our function! Mr. Each loves kittens and wants to play with all four of them. For each kitten, he wants to pets it and make it purr.


And so Mr. Each pets Bob, and Bob purrs.


When Mr. Each is done playing with Bob, he moves on and pets Spot. Spot also purrs.


Mr. Each then pets Moe.


And finally Mr. Each pets Squishy, the last cat in the family (array). Mr. Each would have pet more cats in turn if more were there, but this time we only had four kittens.


All the kittens have been played with, and all of them purred. Now that’s one happy kitty family!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>