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
subjectfact 
for loopcan be interchanged with a while loop    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:47.0
has advantage all the information about controlling the loop is kept in one place    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:47.0
has disadvantage it can be slightly harder to read the code of a for loop than a while loop    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:47.0
has example
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
. . .
}
added by: JK, source: Sun Java Tutorial, 2001-10-19 11:36:47.0
has syntax
for(initializer; condition; incrementer)
{
// statements to keep executing while condition is true
}   
source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:47.0
has part incrementor    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:47.0
has part initializer    source: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:47.0
is a subtopic of Loops and Decision Making2001-10-19 11:36:47.0
is a kind of loop statementsource: Object Oriented Software Engineering by Lethbridge and Laganière, 2001-10-19 11:36:47.0
is a kind of loop statementadded by: JK, source: Sun Java Tutorial, 2001-10-19 11:36:47.0
loop statementhas purpose to execute a section of code more than once2001-10-19 11:37:19.0
statementis terminated by a semicolon    2001-10-19 11:37:57.0
should be not more than one line long if possible2001-10-19 11:37:57.0
syntactic unithas syntax rule
bold = mandatory
italic = non-terminal
normal font = optional
2001-10-19 11:38:04.0