Implement for loops.

Fixes #6183