Its recursion which maybe throwing you off
If I replace the for loop with a while...
Code:
private static void permute(int n) {
permutation[n] = ++path == 0 ? null: words[path-1];
if(path == words.length) {
write();
} else {
i=0
while( i<words.length) {
if(permutation[i] == null)
permute(i);
// You return HERE
++i;
}
}
path--;
permutation[n] = null;
}
Where I comment YOU RETURN HERE is where, by golly, you return after each recursion (see the method calls itself)
Now when it does the value of i in the loop & the original value of n (the argument) will return to what ever was pushed on the stack at that call, and so the while loop will continue, ++i is it still less?
yes is it a null yes push it all on the stack and call myself again
or no
path --
make n null
return
(and if it was a recursive call that called it it will again jump back into the while loop)
Hope that helps