continue only skips one iteration, but it runs multiple times.
On the first iteration, last = prev + j makes prev == last true, and then after that, it stays true because continue skips the rest of the loop iterations.
How do you get ab? It's the first iteration of a-b and the first iteration of b-c.
Since this is an exercise, I won't try to give a fix, but there are multiple other ways you can get what you want, which is to not have repeated characters when two ranges are combined.