I want to combine both the for loops into single for loop. How can i do that?
I want to loop through a to z, and A to Z, like so:
char ch;
for (ch = 'A' ; ch <= 'Z' ; ch++ )
{
}
for (ch = 'a' ; ch <= 'z' ; ch++ )
{
}
but using a single loop.
Using String module ascii_lowercase method returns all lowercase alphabets as a single string abcdefghijklmnopqrstuvwxyz so the program is simply running a for loop over the string characters and printing them. Similarly for uppercase A to Z letters.
for (char ch = 'A' ; ch <= 'z' ; ch == 'Z' ? ch = 'a' : ++ch )
{
}
Should work -- though please, please, don't inflict this on your fellow developers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With