For-loop to While-loop Equivalence

for (a; b; c)
  d;

The first clause of the for-loop is the initialization, the second is the boolean expression that is the condition, the third is the increment.

Keep in mind that the increment occurs at the end of each iteration. So, in general, the conversion of that generic for-loop to a generic while-loop is this:

a;
while (b)
  d;
  c;

Or I could label it like this:

for (initialization; condition; increment)
  doStuff();

is the same as:

initialization;
while (condition)
  doStuff();
  increment;

However, there are some minor differences:


          Created: March 7, 2014
       Last Updated: August 16, 2014
Completed in full by: Michael Yaworski