Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 5

JAVA Loops

while Loop
 The while loop performs a test and continues if the expression evaluates to true.
 The while statement evaluates expression, which must return a boolean value. If the
expression evaluates to true, the while statement executes the statements in the while
block.
 The while loop, shown in the slide, iterates through an array by using a counter.
 There is also a do-while loop, where the test after the expression has run at least once.
 The difference between do-while and while is that do-while evaluates its expression at the
bottom of the loop instead of the top.
while Loop
for Loop
 The for statement provides a compact way to iterate over a range of values - it
repeatedly loops until a particular condition is satisfied
 A counter is initialized and incremented for each step of the for loop shown in
the slide.
 When the condition statement evaluates to false (when i is no longer less than
9), the loop exits.
for Loop

You might also like