$inc is initalialised as 2. Then after each loop iteration, $inc = 6 - $inc results in the sequence 2, 4, 2, 4, ...

All multiples of a prime are composite. The idea of skipping even numbers greater than 2 is that they are all congruent to 0 (mod 2), meaning they are all multiples of 2. Thus, it is perfectly safe to skip all multiples of 3 greater than 3 without fear of skipping any primes.

The reason the incrementation scheme works is that, we start with 5, which is congruent to 2 (mod 3). We add 2, which results in 2 + 2 = 4 is congruent to 1 (mod 3). Next we add 4, which is congruent to 1 (mod 3). 1 + 1 = 2 is congruent to 2 (mod 3). This is a cycle with period 2. In addition, we are guaranteed to avoid all multiples of 2 because we are always performing 1 + 0 = 1 is congruent to 1 (mod 2). It can be seen that it is not possible to choose numbers lower than 2, 4, 2, 4, ... with the desired properties, thus we skiponlymultiples of 2 and 3 greater than 2 and 3, respectively.

Possibly it looks easier considering everything mod 6, but it is up to preference. What we are doing is picking all the numbers that are congruent to 1 or 5 (mod 6).

If we wanted to be very ambitious, we could work out an incrementation scheme that avoids multiples of 5 greater than 5, and so on. However, optimization often comes at the cost of legibility of code.

Note that a verybadway to avoid multiples of 5 is to test $i % 5. This is because % is a computationally expensive operation, compared with + and - which are computationally cheap.