Java   View all facts   Glossary   Help
syntactic unit > statement > control flow statement > loop statement > for loop
Next loop statementwhile loop    Uploop statement    Previous loop statementdo-while loop   

for loop comparison table
Subject have syntax have example have disadvantage has part is a kind of interchange with have advantage
loop statement    control flow statement  
for loop
for(initializer; condition; incrementer)
{
// statements to keep executing while condition is true
}
a is an array of some kind 
. . .
int i;
int length = a.length;
for (i = 0; i < length; i++) {
. . .
// do something to the i th element of a
. . .
}
it can be slightly harder to read the code of a for loop than a while loopinitializerloop statementa while loopall the information about controlling the loop is kept in one place

Next loop statementwhile loop    Uploop statement    Previous loop statementdo-while loop