do … while loop

 

syntax:

 

            do

                statement

            while (logical expression);

 

the while loop is called a pretest loop – it tests the condition prior to executing the body of the loop

 

the do while loop is a posttest loop – it executes the body of the loop, then tests to see if it should execute it again.

 

 

The body of a while loop may never be executed.

The body of a do while loop is executed at least 1 time.

 

 

 

 

For Loop

 

Main use is to simplify the writing of a count controlled loop.

 

for ( initial statement ; loop condition ; update statement)

            statement

 

 

 

this for syntax can translate to a while loop

 

initial statement             // to initialize the loop control variable

 

while (loop condition)               // test the loop control variable

{

           

            update statement           // modify the loop control variable

}