Build the correct range for loops with unusual bounds. Fix from Jay Foad.