write this loop in a way that can be constant folded