Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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.

2 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:


Download ppt "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."

Similar presentations


Ads by Google