Added a for_each function to iterate through ranges