In this example,we’ll learn how to print alphabet characters in C# using for loop, while loop and do while loop.
C# program to print alphabets on screen, i.e., a, b, c, …, z; in lower case.
Source Code:
1 2 3 4 5 6 7 8 9 10 11 | static void Main() { char ch; for (ch = 'a'; ch <= 'z'; ch++) { Console.Write(ch + " "); } Console.ReadKey(); } |
Output:
You can easily modify the above java program to print alphabets in upper case.
Source Code:
1 2 3 4 5 6 7 8 9 10 11 | static void Main() { char ch; for (ch = 'A'; ch <= 'Z'; ch++) { Console.Write(ch + " "); } Console.ReadKey(); } |
Output:
Printing alphabets using a while loop.
1 2 3 4 5 6 7 8 9 10 11 12 | static void Main() { char c = 'a'; while (c <= 'z') { Console.Write(c + " "); c++; } Console.ReadKey(); } |
Output:
Using a do .. while loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 | static void Main() { char c = 'A'; do { Console.Write(c+" "); c++; } while (c <= 'Z'); Console.ReadKey(); } |
Output: