Loops in any programming language are used to execute or run a set of instructions also called functions continually until the conditions become true.

In the Java programming language, basically, four types of loops:

  1. For Loops
  2. For-Each Loops
  3. While Loops
  4. Do-While Loops

1.For Loops:

public class Loops {

public static void main(String[] args){

// here first I will declare an array like

int[] array = {1,2,3,4,5,6,7,8};

for(int i =0;  i<8;  i++){

System.out.println(array[i]);

}

}

}

2.For-Each Loops

public class Loops {

public static void main(String[] args){

// here first I will declare an array like

int[] array = {1,2,3,4,5,6,7,8};

for(int i :array){

System.out.println(i);

}

}

}

To Know the Functionality of the Loops, Just watch the video, where you can find the step to step-wise tutorials on Loops Operations in Java:

3. While Loops:

public class Loops {

public static void main(String[] args){

// here first I will declare an array like

int[] array = {1,2,3,4,5,6,7,8};

int i =0;

while(i<array.length){

System.out.println(array[i]);

i++;

}

}

}

4. Do-While Loops:

public class Loops {

public static void main(String[] args){

// here first I will declare an array like

int[] array = {1,2,3,4,5,6,7,8};

int i =0;

do{

System.out.println(array[i]);

i++;

}

while(i<array.length){

}

}

}

Connect with us: