Code formatting. Added spaces between if ( and for (
Reordered the switch statement and adding comment to make the behaviour less ambiguous.