In this code example, all letters of the alphabet are passed through and output with a for loop.
#include <iostream>
using namespace std;
int main () {
char c;
for (c = 'A'; c <= 'Z'; c++) {
cout << c << ", ";
}
return 0;
}
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
Here’s how the code works:
char
variable c
.for
loop header, set the initial value of c
to 'A'
.c
is less than or equal to 'Z'
.c
is printed to the console, followed by a comma and a space.