Rewrote more of loop protection to carefully walk new lines

This ensures we catch multi-line loop conditions, and fixes #725.
Merge pull request #728 from remy/fix/loop-rewrite-with-brackets

Rewrote more of loop protection to carefully walk new lines