ForIsConditional
DRAFT

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

Correction
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);
}

Symptoms
How do you know your students might have this misconception?

Here is an example of a symptom that might indicate this misconception (for a while instead of a for loop):

When asked what happens in the following code, the answer stated that if the condition was true, “crash” would be printed. While that statement is not incorrect, it is not complete: it does not state that “crash” will be printed repeatedly.

while (true) {
  System.out.println("crash");
}

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.