Agreed, @Chrisir.
My examples were intended to answer the original poster’s query by demonstrating that the increment in a for loop can vary. The examples should have been accompanied by a caveat.
In general, the header of a loop should be a simple control structure, with the bulk of the functionality contained in the body of the loop.
The second example was inspired by this code from the official Python web site:
def fib(n):
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
fib(1000)
As we can see, the work was performed, quite appropriately, in a while loop. But that algorithm presented an opportunity to demonstrate what could, but not necessarily what should, be done in a Java for loop header. In my example, all of the work except the output was performed in a for loop header.
So, with the caveats having been stated above, let’s carry that example to an even further extreme. Here is the loop again, with all the work contained in a header, and with no loop body at all:
void setup() {
for (int a = 0, b = 1, c;
a <= 144;
c = a, a = b, b = c + a, println(c));
}
Caveat: don’t program in this manner. 