wherefor (initialization; termination; increment) { statements }
initialization
is a statement that initialize the loop and
is executed once at the beginning of loop;termination
is a statement that evaluates to a boolean
value (i.e. true
or false
) and determines whether the
loop is terminated or continued;increment
is a statement that gets invoked at each
iteration step.Any (or all of these components can be empty statements (a single semicolon by itself).initialization; while (termination) { statements; increment; }
represents an infinite loop that can only be terminated by an explicitfor (;;) { statements }
break
statement.
A common example is the following loop in which the arguments of a Java application are handled one-by-one and printed in reverse format.
When you run this application with the arguments "public class ReverseWords { public static void main(String args[]) { for (int i=0; i<args.length; i++) { System.out.println( (new StringBuffer(args[i])).reverse() ); } } }
madam
is a palindrome
", then you will see on you terminal screen the lines
madam si a emordnilap