In these passages, King David, says the following: “Before I was afflicted I went astray, but now I keep Thy Word.” David also wrote, “It is good for me that I was afflicted, that I may learn Thy statutes.” I believe that people must be motivated to turn away from sin. The Bible says that we are all born with a sinful nature. Therefore, it is natural for us to commit sins and it is unnatural for us to turn away from sin. We are not motivated to resist temptation and avoid sin. God provides us with that motivation.
The Bible says that we will be punished or chastised for our sins. We may be physically afflicted. We gain motivation to turn from sin when we recognize the linkage between our sins and the affliction that we suffer. That becomes strong motivation because we don’t want to suffer again. We gain further motivation not to sin when we realize the blessings we receive for walking rightly before God. Temptations will still occur, but we are better able to resist them when we are motivated to do so.