Use loop over variable names to remove duplicate code.