Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times. Repeat these statements for each odd number between 5 and 27. indefinite loop: A loop where it is not easy to know how many times it will execute. Repeat these statements until the user types a valid integer. Repeat these statements while the number n is not prime. Repeat these statements until a factor of n is found.
The while loop statement The while loop is a new loop statement useful for writing indefinite loops. The while loop, general syntax: while (<condition>) { <statement(s)> ; } Example: int number = 1; while (number <= 200) { System.out.print(number + " "); number *= 2; OUTPUT: 1 2 4 8 16 32 64 128