How to use For loop


"For" loop is a very famous loop. As you can see below it takes three parts as its condition or expression. The first part is said "Initialization". The second one is said "Termination". And the third one is said "Iteration". Initialization initializes the variable that the loop operates on. Termination checks if the loop should be executed. And iteration increases or decreases the value of the variable that the loop operates on.

public class For_Demo
{
        public static void main(String[] args)
        {
                for(int var = 1; var <= 10; var++)
                {
                        System.out.println(var);
                }
        }
}

0 comments:

Post a Comment