Web server on xp - Chapter 6: Controlling Program Flow with Loops 127

Chapter 6: Controlling Program Flow with Loops 127 Repeating a Certain Number of Times (Java for Statements) Write I will not talk in class on the blackboard 100 times. What your teacher really meant was, Set the count to 0. As long as the count is less than 100, Write I will not talk in class on the blackboard, Add 1 to the count. Fortunately, you didn t know about loops and counters at the time. If you pointed out all this stuff to your teacher, you d have gotten into a lot more trouble than you were already in. One way or another, life is filled with examples of counting loops. And computer programming mirrors life or is it the other way around? When you tell a computer what to do, you re often telling the computer to print three lines, process ten accounts, dial a million phone numbers, or whatever. Because counting loops are so common in programming, the people who create programming languages have developed statements just for loops of this kind. In Java, the statement that repeats something a certain number of times is called a for statement. The use of the forstatement is illustrated in Listings 6-2 and 6-3. Listing 6-2 has a rock-bottom simple example, and Listing 6-3 has a more exotic example. Take your pick. Listing 6-2: The World s Most Boring for Loop import static java.lang.System.out; class Yawn { public static void main(String args[]) { for (int count = 1; count <= 10; count++) { out.print( The value of count is ); out.print(count); out.println( . ); } out.println( Done! ); } }
The UK has been a member of the European Union since 1973. The attitude of the present government towards further integration is conservative, with the official opposition favoring a return of some powers and competencies to the UK.From our experience, we can recommend Cheap UK Web Hosting services.

Leave a Reply