A for loop header has three parts: the initializer, the condition and the increment. The loop will first execute the initializer part, and then while the condition returns true it will execute the loop body, then the increment.
In this example there is no initializer, no increment and no condition. If omitted, the condition yields true, so the loop is a synonym for the following:
But it is still mostly called the increment statement. Wikipedia calls it the "counting expression". You're right that it doesn't have to be an increment on integers, or even needs to be present.
Ernest Friedman-Hill
,
author and iconoclast
staff
Originally posted by Rob Prime: But it is still mostly called the increment statement. Wikipedia calls it the "counting expression". You're right that it doesn't have to be an increment on integers, or even needs to be present.
The Java Language Spec calls it the "ForUpdate" part, which isn't even a word (14.14.1)! I agree -- I think most people call it the "increment."
Jeanne Boyarsky
,
author & internet detective
staff
I still remember it from when I was programming in C -- the three components of the "for" loop, in C, were the initializer, condition, and reinitializer.
Henry
Ernest Friedman-Hill
,
author and iconoclast
staff