4 For whatsoever things were written aforetime were written for our learning, that we through patience and comfort of the scriptures might have hope. Wider context: Living to Please Others 15 We who are strong must be considerate of those who are sensitive about things like this. We must not just please ourselves. 2 We should help others do what is right and build them up in the Lord. 3 For even Christ didn’t live to please himself. As the Scriptures say, “The insults of those who insult you, O God, have fallen on me.” 4 Such things were written in the Scriptures long ago to teach us. And the Scriptures give us hope and encouragement as we wait patiently for God’s promises to be fulfilled. (NLT)
ESV - 4 For whatever was written in former days was written for our instruction, that through endurance and through the encouragement of the Scriptures we might have hope.
For follow-up discussion and general commentary on the topic. Comments are sorted chronologically.