Declaring & Initialising variables in for loop

Regarding this code:

for (int32 Index = 0, Comparison = Index + 1; Comparison < Word.Len(); Comparison++)
    {
         //do stuff
    }

I was a little confused when the instructor added:

, Comparison = Index + 1

To the loop; until i realised it was similar (not the same due to a difference in scope) from declaring multiple variables on one line like the following:

int32 Index=0, Comparison=Index+1;

I don’t recall the instructor mentioning declaring variables on one line in much depth and I thought it might be worth a quick reminder so that line of code is less intimidating.

Privacy & Terms