Lets explain what the variable and mixin is doing.
$alternating-colors: is the variable that contains all the colours you want to display as nth-child selectors. The amount of colours here will be calculated and automatically define the nth-child position selector.
@mixin alternating-background: is a mixin that calculates the amount of colours in the variable, creates position selectors per colour and automatically assigns the correct colour to the correct positional selector.
It does a @for control directive which then calculates each increment ($i) from the first value in your variable colour then calculates how many colours you have in your variable using length($alternating-colors). Within that it then calculates the length of the variable colours again, giving you the value :nth-child(6n) then it works out which increment of