create a for loop that iterates through all possible allcaps strings of length 6 in csharp

You can use nested for loops to iterate through all possible all-caps strings of length 6:

main.cs
for(char c1 = 'A'; c1 <= 'Z'; c1++) {
    for(char c2 = 'A'; c2 <= 'Z'; c2++) {
        for(char c3 = 'A'; c3 <= 'Z'; c3++) {
            for(char c4 = 'A'; c4 <= 'Z'; c4++) {
                for(char c5 = 'A'; c5 <= 'Z'; c5++) {
                    for(char c6 = 'A'; c6 <= 'Z'; c6++) {
                        string allCapsString = $"{c1}{c2}{c3}{c4}{c5}{c6}";
                        // code block to be executed for each all-caps string
                    }
                }
            }
        }
    }
}
514 chars
15 lines

This code iterates through every possible all-caps string of length 6 by nesting six loops. You can replace the code block with whatever you need to do with each string. Note that this will produce 26^6 (308,915,776) strings, so the code block should be as efficient as possible.

related categories

gistlibby LogSnag