138 Part II: Writing Your (How to cite a web site) Own Java Programs
138 Part II: Writing Your Own Java Programs Figure 6-7: The code in Listing 6-5 starts running. Listing 6-5 has a loop within a loop within a loop. The Roomloop is inside of the Suspectloop. Not only do you loop through all the rooms, but you loop through all the rooms six times once for each of the six suspects. If I count them up, that makes 54 visits to various rooms. The Weaponloop is inside of the Roomloop. So every time you visit a room (and you visit a room 54 times), you go through all six of the hideous weapons. Like the code in Listing 6-3, this section s Clueprogram nests statements within other statements. In Listing 6-3, I nested switchstatements inside a big forstatement. But in the Clueprogram, I nest forstatements inside other forstatements. It may look at bit tangled at first, but when you get used to it, nesting loop within loop is a really useful technique. Grouping things together Java provides lots of ways for you to group things together. In Chapter 11, you can group things into an array or a collection. In this chapter, you group things into an enumtype. (Of course, you can t group anything unless you can pronounce enum. The word enum is pronounced ee-noom, like the first two syllables of the word enumeration.) Creating a complicated enumtype isn t easy, but to create a simple enum type, just write a bunch of words inside a pair of curly braces. Listing 6-5 has three enumtypes. The names of the enumtypes are Suspect, Room, and Weapon. When you define an enumtype, two important things happen: You create values. Just as 13and 151are intvalues, mustardand plumare Suspect values.
Have all the commercials and ads about web hosting companies given you headache? Relax now.Our recommendation is web hosting comparisons.