DRAFT
ForIsConditional
Misconception:
The body of the for
-statement executes either one or zero times
depending on whether the condition holds or not.
Incorrect
The body of a for statement executes at most once
Correct
The body of a for statement executes repeatedly, as long as the condition holds
CorrectionHere is what's right.
Here is what's right.
The body of the for
loop executes zero or more times. It executes as long as the loop condition is true
.
For example, the body of the following for
loop (the System.out.println(i)
statement) executes exactly 3 times (for i=1
, i=2
, and i=3
).
for (int i=1; i<=3; i++) {
System.out.println(i);
}
Language
Java