for loop
In this article we will learn about for loop in Java. The Java for loop is used to iterate a part of the program several times. If the number of iteration is fixed, it is recommended to use for loop. Three types of for loop 1. Simple for loop Syntax for (initialization ; condition ; increment/decrement ){ //code to be executed } Program public class For_loop { public static void main( String args[]) { for ( int i= 1 ; i<= 5 ; i++) { System.out.println(i); } } } Run Explanation Here, i=1 is an initialization from where the for loop starts. i<=5 condition where for loop ends. i++ is incrementation which increment the i variable in each iteration. Remember that in this for loop variable i is accessible only through this for loop. Outside of for loop variable i is not accessible. 2. for each loop Syntax for ( Type var : array){ //code to be executed } Pr...