Habits are a tricky thing. Your brain and your body don't apply morality to habits. Your conscience and circumstances determine if the habit is good or if it is bad. And to make things even trickier is that a habit can change from good to bad over time.
But habits are an empirical ergonomic element of your being. They increase your productivity and make the mental and physical process of performing the habitual task more efficient and more rewarding.
Understanding what a habit is and how it is formed is the first step to establishing good habits and breaking bad ones. Habits can be a great boon to your life. But they can also be a life long struggle to deny if they aren't the right ones.
Forming a habit is the same process whether it is a good habit or a bad habit. The main difference is that what we consider to be good habits usually take concentrated effort. While bad ones are easy to fall into. I could easily eat a donut everyday, but it would be a better habit to eat an apple everyday instead.
Breaking a habit is hard. Sometimes it is impossible to remove the offending habit. In that case you don't actually break it you just avoid it and replace it with a good habit.