Unto the Third and the Fourth Generation

At least four passages of the Old Testament talk about God punishing the descendants of evil men down to the third and fourth generations.  How could a loving God do this?