What makes you think that the reason to rewrite code is because “my code is so bad”? The reason most of us have to rewrite code if because contexts change, all the time.
Maybe you had to solve a problem at that given time with the knowledge of the domain you had, and that’s it. But situations evolve, business rules morph or change, maybe performance NOW is an issue but not at the time the software was conceived, hell, even knowing now different skills or a new language may be the case.
So, yes, every single cycle the code is better.