I had the trouble of understanding this myself a very long time ago then I found an article in LearnEnglish at https://learnenglish.britishcouncil.org.
The article Past habit – used to/would/past simple says that:
When we talk about things that happened in the past but don’t happen anymore we can do it in different ways. we can use "used to", "would" or the Past Simple.
- We can use ‘used to’ to talk about past states or repeated past actions:
- We used to live in New York when I was a kid.
- I used to smoke but I gave up a few years ago.
Remember that ‘used to’ is only for past states/actions that don’t happen now – we can’t use it for things that still happen now.
- We can use ‘would’ to talk about repeated past actions, however, we can't use it speak about past states.
- My teachers would always say “Sit down and shut up!”
- We would live in New York when I was a kid. (Incorrect)
Often either ‘would’ or ‘used to’ is possible. Both of these sentences are possible:
- Every Saturday, I would go on a long bike ride.
- Every Saturday I used to go on a long bike ride.
- We can use the past simple in the same way as ‘used to’ and ‘would’ to talk about repeated past actions. We can also use the past simple for past states.
- We went to the same beach every summer.
- I went to Egypt in 1988.
However, if something happened only once we can’t use ‘used to’ or ‘would’ – we must use the past simple.
Based on what the British Council tells us, "When I worked as a teller, I had a decent income." and "When I used to work as a teller, I had a decent income.", and even "When I would work as a teller, I had a decent income." all mean the same thing; a repeating action in the past.
However, "When I went there, I was the top student." - we can use "when" with Past simple only to speak about past habits and states. So this sound awkward. It can mean two different things:
The second sentence "When I used to go there, I was the top student." means only one thing:
- Whenever I went there in the past, I was the top student. (Now again, you already were a top student whenever you went there)
I doubt that Past habits are possible in if-clauses but they are possible in when clauses and even in while clauses. Compare:
- I could never understand harmony when I used to play guitar. (He doesn't play guitar anymore, but when he had the habit of playing it he couldn't understand harmony. He may be playing another instrument now)
- When I used to play guitar, I could never understand harmony.
And with a while clause:
- It wasn't easy to throw up playing football due to the trauma while I used to do it everyday. (At the time when I used to play football everyday it was hard to throw up doing it)
I also wish to notice that "used to" and Past Simple mostly focus on the habit, not its duration or frequency unlike "would", which expresses that an activity was routine, typical behavior, having duration or frequently repeated.
There are few notes on how to use "used to", "would", and Past Simple:
- Use "would" for a custom. Use "used to" for a discontinued habit.
- In the past, people used to call a person on his or her birthday. (Incorrect)
- In the past, people would call a person on his/ her/ their birthday. (Correct)
- Don't use an adverb of time with "used to". Either remove the adverb, change the verb to past tense when using an adverb for time or use a time-relative clause to refer to an earlier stage of life.
- Last year, I used to study very hard. (Incorrect)
- Last year, I studied very hard. (Correct)
- I used to study very hard. (Correct)
- When I was in college, I used to study very hard. (Correct)
- "Used to" is not used with a quantity of time. Use past tense with a quantity of time.
- I used to live in San Diego for five years. (Incorrect)
- I used to live in San Diego. (Correct)
- I lived in San Diego for five years. (Correct)
- Don't use a repeated adverb of time, use the past tense or an adverb of frequency instead.
- I used to go to the gym several times. (Incorrect)
- I went to the gym several times. (Correct)
- I often used to go to the gym. (Correct)