In this tutorial, We will discuss for use and implementation of for loop in java.
for Loop in Java
In this tutorial, We will discuss for use and implementation of for loop in java. The for loop is the type of looping construct. It also works as while loop construct but it provide the initialization, condition and the increment is same written in the for construct. All the statements which has to be executed written in the for block.
Syntax of for loop-
for( initialization; termination; increment)
{
statements;
}
In the given example we will print a simple expression 5 times as-
Code:
package com.devmanuals2; public class ForExample { public static void main(String[] args) { int i; for(i=1;i<=5;i++){ System.out.println(i+" Times"); } } }
Output:
1 Times 2 Times 3 Times 4 Times 5 Times |
[ 0 ] Comments