Only 3 times
It takes an action only 3 consecutive times to form a basis of a habit pattern.
If this action is particularly comforting to our nerves, keeps us in our comfort zones and does not push us for an effort, our brain shall most likely stick to it.
A habit is formed. At this point, the brain is not concerned about the impact of this habit on our health, career, quality of relationships, mental growth, ability to solve problems, or ability to stay focus etc .