Writing a Program
Yesterday was filled with errands, a doctor appointment, and testing breadfruit recipes for an upcoming recipe book (not mine; I'm just a tester). I ended up with only two hours to work on learning java before my brain turned off and I had to go to bed. Today I'm trying to catch up...
Chapter 5 is where I get to create a real game program. In this case, it's a very simple version of Battleship although instead of ships we're killing Dot Coms. Supposedly, that makes the book a business expense... The book hasn't covered how to create user interfaces yet so everything is still command line driven. Somewhere in chapter 14 I'll get to learn the really cool stuff but right now I'm still figuratively learning to tie my shoelaces.

What we are learning in this chapter:
Loop de loop

While is used when you don't know how many times you need to repeat the loop; you just want it to continue looping until some condition is met. A game where you keep going until you get "killed" would be an example.
The regular for loop is used when you know how many times you want to cycle through the loop. You normally set the counter to zero to start and then specify how many cycles to do. You might use this type of loop when printing out the lyrics to "100 Bottles of Beer (On the Wall)".
The enhanced for is used for traveling through the members of an array (and other "collections" that I haven't learned about yet) You can think of this type of loop as the "for each" loop because it reads "FOR EACH thing in the collection do this...." You might use this type of loop in a children's game, "for each cupcake in the tin, frost it".

And we learn to change a string into an int. Don't ask.

0 comments:
Post a Comment