Repeating Structures Do While Loops. Do While Loop While loops have a test condition before the loop...

3
Repeating Structures Do While Loops

Transcript of Repeating Structures Do While Loops. Do While Loop While loops have a test condition before the loop...

Page 1: Repeating Structures Do While Loops. Do While Loop While loops have a test condition before the loop –This means that java will test the condition before.

Repeating Structures

Do While Loops

Page 2: Repeating Structures Do While Loops. Do While Loop While loops have a test condition before the loop –This means that java will test the condition before.

Do While Loop• While loops have a test condition before the loop

– This means that java will test the condition before entering the loop

– It is possible that the instruction inside a while loop will be skipped entirely

• do-while loops are similar, but have the test condition at the end of the loop– This allows the instructions in the loop to be executed at least

once before the condition is tested– Since the condition variable is tested after at least one iteration of

the loop, the initialization before the loop is not always necessary• You can actually set the test variable within the loop!• However, if you want your test variable to have an initial variable,

make sure you set it OUTSIDE the loop. Or else you will continue set the variable to this initial condition every time the loop is iterated

Page 3: Repeating Structures Do While Loops. Do While Loop While loops have a test condition before the loop –This means that java will test the condition before.

General Do While Loop Structure

<initialization if needed>

do {

<instructions, can have more than 1>

<way of making test condition false>

} while (<test condition>);

braces brackets

indent

semicolon