The pressCount variable starts with a value 0 above the setup and the loop. As long as it stays 0, nothing will happen because there are no conditions based on pressCount == 0.
The code is still running through the loop hundreds of times per minute, but there just isn’t anything for it to do.
As soon as the digitalRead function receives a LOW signal, the pressCount variable increases by 1. Now the first ‘if’ statement is true: pressCount == 1. The effect is that the code between the { and } runs, turning pin 10 LOW and pin 11 HIGH.
Why do you ensure that pin 10 is turned LOW? When the code loops back through from pressCount = 3 to pressCount = 1, pin 10 will be HIGH, since that’s which LED is on if pressCount = 3. If you don’t ensure that 10 is LOW, you’ll end up with a mixed color when pressCount = 1.
The loop continues to run, checking the if statements each time through (hundreds of times per second). As soon as digitalRead(A5)==LOW again, the pressCount increases by one. Now that pressCount is equal to 2, the first if statement in the loop is false.
The computer now checks the first else-if statement. Is pressCount equal to 2? Yes, so the code between that statements curly braces will run.
Remember that at this point, the code has never checked the condition of the second if-else statement. Once the code finds a true statement, it runs that and skips the other else-if statements. That is what makes else-if different from if. Every if statement is checked, but not every else-if statement is checked.
When the button is pressed for a third time, pressCount now equals 3 and that else-if statement is true, so the last light will turn on.
Notice that the last else-if sets pressCount back to 0 as a part of its action. Because pressCount ==0 doesn't do anything, the light for the third else-if statement stays on until pressCount equals 1 again.
You can see in the ‘if digitalRead(A5) ==LOW” statement that there is a delay of 250 milliseconds. This keeps the code from running too quickly and increasing pressCount by 2,3, or more each time you press the button. Holding the button for more than 250 milliseconds, though, will increase the pressCount variable by more than one. Play with that delay and see how it changes the strobing effect between the colors.