Zebra0.com

java loopsJava

Java

Learn Java in step-by-step lessons.

For Loops

Loops

A loop is a block of statements that is repeated. Java has three types of loops: while, for and do.

A loop has a Boolean expression to test. If the expression is true the statements in the block are executed and then the test is performed again. When the condition is false, the next statement after the loop is executed. A while loop and a for loop test a Boolean expression at the beginning, a do loop tests the Boolean expression at the end. While and for loops are executed zero or more times. Do loops are always executed at least once.

The Boolean expression is a check point: The decision is made to execute the entire loop or not. If the value of the Boolean expression changes during execution of the loop, the loop continues until the test is made again. The loop does not end in the middle if the variable changes.

Each pass through the loop is called an iteration.

Please study the material at each of the links below.

  1. Read 3 numbers without loop

  2. Read number and add to total 3 times

  3. A for loop to read 3 numbers

  4. Endless Loops

  5. Ask how many numbers

  6. For loop counts from 10 down to 1

  7. For loop counts by 5

  8. Multiply to generate power of 2

  9. For loop to print the alphabet

GlossaryGlossary for loops lesson
Full Glossary