This question already has answers here: Closed 8 years ago .

Lets say I have the letters

a b c d

and I want to get every single possible pattern/combination of these letters in a string that is 4 letters long.

aaaa baaa caaa daaa abaa acaa acad abba

and so on.

What loop or pattern can I use to list every combination possible?

I am writing this in C#, but examples in C++ and javascript are welcome as well.

My current idea only increments one letter for each letter possible. Then shifts to the right once and repeats. This doesn't cover patterns like.