News:

11 March 2016 - Forum Rules

Main Menu

One liner to print the alphabet.

Started by InfamousKnight, September 02, 2012, 02:51:43 PM

Previous topic - Next topic

InfamousKnight

for(char c = "A"; c <= "Z"; c++) cout << (char)c << ' ';

Now why I'm type casting with the same data type is because chars are ints as well. So without that type cast, the compiler would assume your talking about integers.

Tell me what you think.

LostTemplar


henke37

Way too many characters, you can combine the loop iterator increment with the output. Also, you got the wrong type of quotes for the character literals.

InfamousKnight

Quote from: henke37 on September 02, 2012, 03:14:09 PM
Way too many characters, you can combine the loop iterator increment with the output. Also, you got the wrong type of quotes for the character literals.

You mean like "A" should be 'A' and "Z" should be 'Z'? Yeah, I suppose. I kinda just rushed through this post.

BRPXQZME

Quote from: InfamousKnight on September 02, 2012, 02:51:43 PM
So without that type cast, the compiler would assume your talking about integers.
No, it would assume a char unless told otherwise.
we are in a horrible and deadly danger

uyuyuy99

I don't see what's so special about this. You could write a huge program on a single line if you wanted to... line breaks are just whitespace, they're not that meaningful.

Kiyoshi Aman


print for ('A' .. 'Z');


My Perl one-liner is unbeatably shorter than your C++ one-liner. Now leave.

InfamousKnight

Quote from: Kiyoshi Aman on September 08, 2012, 05:30:30 PM

print for ('A' .. 'Z');


My Perl one-liner is unbeatably shorter than your C++ one-liner. Now leave.

You just made perl look like the best language there is!

BRPXQZME

Quote from: uyuyuy99 on September 08, 2012, 05:10:57 PM
I don't see what's so special about this. You could write a huge program on a single line if you wanted to... line breaks are just whitespace, they're not that meaningful.
They're better when you're not trying to do anything you're going to have to look at again.

That means in languages tooled towards building lasting applications and systems (such as any C-like), you should avoid them, unless you're submitting an IOCCC entry or something too clever by half like that.
we are in a horrible and deadly danger

Zoinkity

The great irony of Python: despite the style rules calling for clear code and avoidance of one-liners, it winds up being the source of the longest example on the wiki article.

The one case where whitespace should be avoided would be in small-memory systems, like old Basic machines or, as a modern example, graphing calculators.  Again, due to readability you'd want to avoid removing whitespace until after you're done debugging.

Never heard of IOCCC before, but wow there's some neat concepts there.

Kiyoshi Aman

Oh! Oh! Are we gonna complain about significant whitespace? Are we?

Because COBOL is far worse than Python.

BRPXQZME

QuotePhoenician is a dead language. Mayan is a dead language. Latin is a dead language. What makes these languages dead is the fact that no one speaks them anymore.
Maybe not so much the Latin, but I imagine this statement would come as a shock to speakers and scholars of Mayan languages.
we are in a horrible and deadly danger

Kiyoshi Aman

Nahuatl is still alive and well, for instance, despite being diluted by, and in turn diluting, Spanish.

sa♥tsu

10 PRINT "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Zoinkity

Interestingly, we just got one of those learn Nahuatl <-> Portugese in 36 1/2 minutes types of books in the shop this week.

To be fair, three weeks ago we also got in one listing all the newly invented eclesiastical latin for modern stuff.  So, next time you're planning to use the ATM at the Vatican we've totally got you covered.