C.15. for Repetition Statement

Java also provides the for repetition statement, which specifies the counter-controlled-repetition details in a single line of code. Figure C.13 reimplements the application of Fig. C.12 using for.

 1   // Fig. C.13: ForCounter.java 2   // Counter-controlled repetition with the for repetition statement. 3  4   public class ForCounter 5   { 6      public static void main( String[] args ) 7      { 8         // for statement header includes initialization,  9         // loop-continuation condition and increment     10         for ( int counter = 1; counter <= 10; ++counter )11            System.out.printf( "%d ", counter );          12 13         System.out.println(); // output a newline ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.