Redo #1548 for the master branch

Switch statement within loop doesn't recognize 'continue' if case is
wrapped in { }
Merge pull request #1582 from Famlam/issue1318master

Redo #1548 for the master branch