Add tests to check that the FOR variable is defined after the loop

In PR #3487 I was told that my change "would break a lot of code" but it did not break any test. It would have broken those tests.