while loops are useful when you do not know the number of times you need to iterate beforehand.
Source Code
public class WhileLoopExample {
public static void main(String[] args) {
int i = 1;
while (i <= 5) {
System.out.println("Value of i: " + i);
i++;
}
}
}