A simpler (some would say "more elegant") approach to wrapping back to the beginning is to use the modulo, or remainder, operator.