Site Search:

Compare loop constructs

Back OCAJP


do-while loop check condition at the end of the block execution, the code block is guaranteed to be run at least once.

while loop check condition at the beginning of the block execution, the code block can be totally skipped.

the variable used in the condition test of while loop and do-while loops have to be defined outside of the loop block; the variable defined inside loop block is out of scope in the condition test.

the variable used in for loop's condition test is defined during the for loop initializing, this variable is out of scope outside the for loop. Back OCAJP