Better to cache before then test so only accessing styles.rules.length once per loop (currently accesses twice, once for the if and once for the assignment).