Technical SpeaksCodeForDevelopersThe official blog of Technical Speaks
Core Java

Loops in Java | Java Tutorial | For | While | For-Each | Do-While | Looping in Java

By · Published · Updated · 1 min read

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:

code
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

code
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:

code
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:

code
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:

Written by

Saurabh Kumar

SEO Consultant and Founder of Technical Speaks

Saurabh Kumar is an SEO professional with more than 10 years of hands-on experience and a Top Rated freelancer on Upwork. He is the founder of Technical Speaks and also builds websites with Next.js and WordPress.

Comments

Leave a comment