Loop over variable names to eliminate duplicate code.