Reset loop counters when entering periodic loops.
Merge pull request #1 from lorem3k/patch-1

Reset loop counters when entering periodic loops.