Lucas Lehmer Primality Test
The GMP code on RosettaCode is about 2x faster if you're looking for performance improvements.

It has a reasonable number of comments explaining the various optimizations.  Most of the help will be in the pre-tests, where we know easy ways to find out if the result will be composite.  The test itself is not too dissimilar, with a few different choices made.

I don't particularly like your for loop, which you wrote more like a while loop -- mixing the iteration and test together.