Java For Loop Example


The Java for loop is used When you exactly know how many times the loop should be executed.

For example- Suppose you want to execute “hello” three-time

Program
public class forloop { public static void main(String[] args) { for (int i = 0; i < 3; i++) {//Starting from i=0,0<3 true,then i=1,1<3 true, then i=2,2<3 System.out.println("Hello"); } } }
Input
Output