Lesson 5: Indefinite Iterative Constructs

What is Indefinite Iteration?

An indefinite iteration is a type of iteration where the number of iterations is not known before the loop starts — think of a while loop, which continues until a condition is met.

Worked Example

Print all the even numbers between 1 and 100:

int i = 1;
while (i <= 100) {
  if (i % 2 == 0) {
    System.out.print(i + " ");
  }
  i++;
}

Leave a comment

Your email address will not be published. Required fields are marked *

sponsors Ads