Search code examples
powershellincrementalphabet

Powershell loop with numbers to alphabet


I need help with the following: Create a for loop based on the conditions that the index is initialized to 0, $test is less than 26, and the index is incremented by 1 For each iteration, print the current letter of the alphabet. Start at the letter A. Thus, for each iteration, a single letter is printed on a separate line. I am not able to increment the char each time the loop runs

for ($test = 0; $test -lt 26; $test++)
{
[char]65
}

I have tried multiple attempts with trying to increment the char 65 through 90 with no success. Is there an easier way to increment the alphabet to show a letter for each loop that is ran?


Solution

  • You can sum your loop index with 65. So, it'll be: 0 + 65 = A, 1 + 65 = B ...

    for ($test = 0; $test -lt 26; $test++)
    {
        [char](65 + $test)
    }