Our task is to print the alphabets from A to Z using loops. There are various methods to print alphabets from (A to Z) or (a to z).
- Using ASCII values
- Using character variables.
In this article we will mainly focus on the following programs and their logic:
- Using for loop
- Using the while loop
- Using a do-while loop
 Program to display alphabets using ASCII values
C++
// C++ Program to display alphabets using ASCII values#include <iostream>Â
using namespace std;Â
int main(){    int i;       cout << "Alphabets from (A-Z) are:\n";       // ASCII value of A=65 and Z=90    for (i = 65; i <= 90; i++) {        // Integer i with %c will be converted to character        // before printing.%c will takes its equivalent        // character value        cout << (char)i << " ";    }Â
    cout << "\nAlphabets from (a-z) are:\n";Â
    // ASCII value of a=97 and z=122    for (i = 97; i <= 122; i++) {        // Integer i with %c will be converted to character        // before printing.%c will takes its equivalent        // character value        cout << (char)i << " ";    }    return 0;} |
C
// C Program to display alphabets using ASCII values#include <stdio.h>Â
int main(){Â Â Â Â int i;Â Â Â Â printf("Alphabets from (A-Z) are:\n");Â
    // ASCII value of A=65 and Z=90    for (i = 65; i <= 90; i++) {        // Integer i with %c will be converted to character        // before printing.%c will takes its equivalent        // character value        printf("%c ", i);    }Â
    printf("\nAlphabets from (a-z) are:\n");Â
    // ASCII value of a=97 and z=122    for (i = 97; i <= 122; i++) {        // Integer i with %c will be converted to character        // before printing.%c will takes its equivalent        // character value        printf("%c ", i);    }Â
    return 0;} |
Java
public class Main {    public static void main(String[] args) {        int i;        System.out.println("Alphabets from (A-Z) are:");        // ASCII value of A=65 and Z=90        for (i = 65; i <= 90; i++) {            // Integer i with %c will be converted to character            // before printing.%c will takes its equivalent            // character value            System.out.print((char)i + " ");        }        System.out.println("\nAlphabets from (a-z) are:");        // ASCII value of a=97 and z=122        for (i = 97; i <= 122; i++) {            // Integer i with %c will be converted to character            // before printing.%c will takes its equivalent            // character value            System.out.print((char)i + " ");        }    }} |
Python3
def main():    print("Alphabets from (A-Z) are:")    # ASCII value of A=65 and Z=90    for i in range(65, 91):        # Integer i with chr() will be converted to character        # before printing. chr() will take its equivalent        # character value        print(chr(i), end=" ")Â
    print("\nAlphabets from (a-z) are:")    # ASCII value of a=97 and z=122    for i in range(97, 123):        # Integer i with chr() will be converted to character        # before printing. chr() will take its equivalent        # character value        print(chr(i), end=" ")Â
Â
if __name__ == "__main__":Â Â Â Â main()Â Â Â Â Â # This code is contributed by Dwaipayan Bandyopadhyay |
C#
using System;Â
public class GFG{Â Â Â Â public static void Main()Â Â Â Â {Â Â Â Â Â Â Â Â int i;Â
        Console.WriteLine("Alphabets from (A-Z) are:");                 // ASCII value of A=65 and Z=90        for (i = 65; i <= 90; i++)        {            // Integer i with (char) will be converted to character            // before printing. (char) will take its equivalent            // character value            Console.Write((char)i + " ");        }Â
        Console.WriteLine("\nAlphabets from (a-z) are:");Â
        // ASCII value of a=97 and z=122        for (i = 97; i <= 122; i++)        {            // Integer i with (char) will be converted to character            // before printing. (char) will take its equivalent            // character value            Console.Write((char)i + " ");        }    }} |
Javascript
console.log("Alphabets from (A-Z) are:");Â
// ASCII value of A=65 and Z=90for (let i = 65; i <= 90; i++) {    // Convert the ASCII value to a character and print it    console.log(String.fromCharCode(i) + " ");}Â
console.log("\nAlphabets from (a-z) are:");Â
// ASCII value of a=97 and z=122for (let i = 97; i <= 122; i++) {    // Convert the ASCII value to a character and print it    console.log(String.fromCharCode(i) + " ");} |
Alphabets from (A-Z) are: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Alphabets from (a-z) are: a b c d e f g h i j k l m n o p q r s t u v w x y z
Program to print (A to Z) and (a to z) using for loop
In the below program,
- For loop is used to print the alphabets from A to Z. A loop variable is taken to do this of type ‘char’.Â
- The loop variable ‘i’ is initialized with the first alphabet ‘A’ and incremented by 1 on every iteration.
- In the loop, the character ‘i’ is printed as the alphabet.
Program:Â
C++
// C++ program to find the print// Alphabets from A to Z#include <bits/stdc++.h>using namespace std;Â
int main(){    // Declare the variables    char i;Â
    // Display the alphabets    cout << "The Alphabets from A to Z are: \n";Â
    // Traverse each character    // with the help of for loop    for (i = 'A'; i <= 'Z'; i++) {        // Print the alphabet        cout << i << " ";    }    // Display the alphabets    cout << "\nThe Alphabets from a to z are: \n";    for (i = 'a'; i <= 'z'; i++) {        // Print the alphabet        cout << i << " ";    }Â
    return 0;} |
C
// C program to find the print// Alphabets from A to ZÂ
#include <stdio.h>Â
int main(){    // Declare the variables    char i;Â
    // Display the alphabets    printf("The Alphabets from A to Z are: \n");Â
    // Traverse each character    // with the help of for loop    for (i = 'A'; i <= 'Z'; i++) {Â
        // Print the alphabet        printf("%c ", i);    }Â
    printf("\nThe Alphabets from a to z are: \n");Â
    // Traverse each character    // with the help of for loop    for (i = 'a'; i <= 'z'; i++) {Â
        // Print the alphabet        printf("%c ", i);    }Â
    return 0;} |
Java
// Java program to find the print// Alphabets from A to Zclass GFG {Â
    public static void main(String[] args)    {        // Declare the variables        char i;Â
        // Display the alphabets        System.out.printf("The Alphabets from A to Z are: \n");Â
        // Traverse each character        // with the help of for loop        for (i = 'A'; i <= 'Z'; i++) {            // Print the alphabet            System.out.printf("%c ", i);        }        // Display the alphabets        System.out.printf("\nThe Alphabets from a to z are: \n");Â
        // Traverse each character        // with the help of for loop        for (i = 'a'; i <= 'z'; i++) {            // Print the alphabet            System.out.printf("%c ", i);        }    }} |
Python3
# Python3 program to find the print# Alphabets from A to ZÂ
if __name__ == '__main__':         # Declare the variables    i = chr;Â
    # Display the alphabets    print("The Alphabets from A to Z are: ");Â
    # Traverse each character    # with the help of for loop    for i in range(ord('A'), ord('Z') + 1):Â
        # Print the alphabet        print(chr(i), end=" ");    # Display the alphabets    print("\nThe Alphabets from a to z are: ");Â
    # Traverse each character    # with the help of for loop    for i in range(ord('a'), ord('z') + 1):Â
        # Print the alphabet        print(chr(i), end=" ");        |
C#
// C# program to find the print// Alphabets from A to Zusing System;Â
class GFG{Â
    public static void Main(String[] args)     {        // Declare the variables        char i;Â
        // Display the alphabets        Console.Write("The Alphabets from A to Z are: \n");Â
        // Traverse each character        // with the help of for loop        for (i = 'A'; i <= 'Z'; i++)        {Â
            // Print the alphabet            Console.Write("{0} ", i);        }      // Display the alphabets        Console.Write("\nThe Alphabets from a to z are: \n");Â
        // Traverse each character        // with the help of for loop        for (i = 'a'; i <= 'z'; i++)        {Â
            // Print the alphabet            Console.Write("{0} ", i);        }Â
    }} |
Javascript
<script>Â
// Javascript program to find the print// Alphabets from A to ZÂ
// Declare the variableslet i;Â
// Display the alphabetsdocument.write("The Alphabets from A" +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â " to Z are: " + "</br>");Â
// Traverse each character// with the help of for loopfor(i = 'A'.charCodeAt();     i <= 'Z'.charCodeAt(); i++){         // Print the alphabet    document.write(        String.fromCharCode(i) + " ");}Â
// Display the alphabetsdocument.write("The Alphabets from a" +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â " to z are: " + "</br>");Â
// Traverse each character// with the help of for loopfor(i = 'a'.charCodeAt();     i <= 'z'.charCodeAt(); i++){         // Print the alphabet    document.write(        String.fromCharCode(i) + " ");}Â
</script> |
The Alphabets from A to Z are: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z The Alphabets from a to z are: a b c d e f g h i j k l m n o p q r s t u v w x y z
Program to print (A to Z) and (a to z) using the while loop
In the below program,
- While loop is used to print the alphabets from A to Z. A loop variable is taken to display of type ‘char’.Â
- The loop variable ‘i’ is initialized with the first alphabet ‘A’ and incremented by 1 on every iteration.
- In the loop, the character ‘i’ is printed as the alphabet.
C++
// C++ program to find the print// Alphabets from A to Z#include <bits/stdc++.h>using namespace std;Â
int main(){    // Declare the variables    char i;Â
    // Display the alphabets    cout << "The Alphabets from A to Z are: \n";Â
    // Traverse each character    // with the help of while loop    i = 'A';Â
    while (i <= 'Z') {        cout << i << ' ';        i++;    }    // Display the alphabets    i = 'a';Â
    cout << "\nThe Alphabets from a to z are: \n";Â
    while (i <= 'z') {        cout << i << ' ';        i++;    }Â
    return 0;} |
C
// C program to find the print// Alphabets from (A to Z) and// (a to z) using while loopÂ
#include <stdio.h>Â
int main(){    // Declaring the variable    char i;Â
    // Display the alphabets    printf("The Alphabets from A to Z are: \n");Â
    // Traversing each character    // with the help of while loopÂ
    i = 'A';Â
    while (i <= 'Z') {        printf("%c ", i);        i++;    }Â
    // for lower case alphabets    printf("\nThe Alphabets from a to z are: \n");Â
    i = 'a';Â
    while (i <= 'z') {        printf("%c ", i);        i++;    }Â
    return 0;} |
Java
import java.io.*;public class GFG {    public static void main(String[] args) {        // Declare the variables        char i;        System.out.println("The Alphabets from A to Z are: ");        // Traverse each character using a        // while loop        i = 'A';        while (i <= 'Z') {            System.out.print(i + " ");            i++;        }        // Display the lowercase alphabets        i = 'a';        System.out.println("\nThe Alphabets from a to z are: ");        while (i <= 'z') {            System.out.print(i + " ");            i++;        }    }} |
C#
using System;Â
class Program {    static void Main()    {        // Declare the variable        char i;Â
        // Display the alphabets from A to Z        Console.WriteLine("The Alphabets from A to Z are:");Â
        // Traverse each character using a while loop        i = 'A';Â
        while (i <= 'Z') {            Console.Write(i + " ");            i++;        }Â
        // Display the alphabets from a to z        i = 'a';Â
        Console.WriteLine(            "\nThe Alphabets from a to z are:");Â
        while (i <= 'z') {            Console.Write(i + " ");            i++;        }    }} |
The Alphabets from A to Z are: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z The Alphabets from a to z are: a b c d e f g h i j k l m n o p q r s t u v w x y z
Program to print (A to Z) and (a to z) using a do-while loop
In the below program,
- The do-while loop is used to print the alphabets from A to Z. A loop variable is taken to display of type ‘char’.Â
- The loop variable ‘i’ is initialized with the first alphabet ‘A’ and incremented by 1 on every iteration.
- In the loop, the character ‘i’ is printed as the alphabet.
C++
// C++ program to find the print// Alphabets from A to Z#include <bits/stdc++.h>using namespace std;Â
int main(){    // Declare the variables    char i;Â
    // Display the alphabets    cout << "The Alphabets from A to Z are: \n";Â
    // Traverse each character    // with the help of while loop    i = 'A';Â
    do{        cout << i << ' ';        i++;    }while (i <= 'Z');    // Display the alphabets    i = 'a';Â
    cout << "\nThe Alphabets from a to z are: \n";Â
    do{        cout << i << ' ';        i++;    }while (i <= 'z');Â
    return 0;} |
C
// C program to find the print// Alphabets from (A to Z) and // (a to z) using do-while loopÂ
#include <stdio.h>Â
int main(){    // Declaring the variable    char i;Â
    // Display the alphabets    printf("The Alphabets from A to Z are: \n");Â
    // Traversing each character    // with the help of do while loopÂ
    i = 'A';Â
    do {        printf("%c ", i);        i++;    } while (i <= 'Z');Â
    // for lower case alphabets    printf("\nThe Alphabets from a to z are: \n");Â
    i = 'a';Â
    do {        printf("%c ", i);        i++;    } while (i <= 'z');Â
    return 0;} |
The Alphabets from A to Z are: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z The Alphabets from a to z are: a b c d e f g h i j k l m n o p q r s t u v w x y z
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

