Java Reference
In-Depth Information
in case of false, the body does not execute and control is transferred to the statement
following the for loop.
 After once execution of body of loop, the control is transferred to the update
statement which generally includes increment or decrement. This statement is
generally used to update any loop variable.
 Again there is a evaluation of Boolean expression. If it is evaluated true, the
loop again executes and this process (loop body , then update step, then Boolean
expression) is repeated until Boolean expression is false. As Boolean expression
evaluates false, loop is terminated.
Example:
public class demo {
public static void main(String args[]) {
for(int a = 10; a < 20; a = a+1) {
System.out.print("value of a : " + a );
}
}
}
This program results in printing value of a from 10 to 19. Because as a is incremented to
20 , the condition a<20 is false and loop is terminated.
The while Loop
A while loop also performs the same task as for loop with a small difference which you
will understand with the following syntax and example.
Search WWH ::




Custom Search