Skip to content
Büşra Oğuzoğlu edited this page Jul 3, 2022 · 28 revisions

Loops in Java:

1. While Loop:

2. Do-while Loop:

3. For Loop:

4. For-each Loop:

We generally use this type of loop to iterate over the elements of a list of items. (Could be an ArrayList as an example)

Syntax:

for (type var : array)

{

`statements using var;`

}

It is same as this for loop:

for (int i=0; i<arr.length; i++)

{

`type var = arr[i];`

`statements using var;`

}

5. Nested Loops:

Clone this wiki locally