Simplify control flow for for loops and register target variable assignment