For, While, and Do-While Loops

Loops are used to execute code repeatedly.

For Loop:

for (int i = 0; i < 5; i++) {
  System.out.println(i);
}

While Loop:

int i = 0;
while (i < 5) {
  System.out.println(i);
  i++;
}

Do-While Loop:

int i = 0;
do {
  System.out.println(i);
  i++;
} while (i < 5);
← PrevNext →