To form better habits or break bad habits, we must first understand how habits work. Here is the habit loop by Charles Duhigg.
217