$positions: ( t: ('top'), r: ('right'), b: ('bottom'), l: ('left'), x: ('left', 'right'), y: ('top', 'bottom') ); @for $i from 0 to 5 { @each $var, $value in $positions { @each $prop, $propValue in (m: 'margin', p: 'padding') { .#{$prop}#{$var}-#{$i} { @each $pos in $value { #{$propValue}-#{$pos}: ($i * .5) + 'em'; } } } } }