[prog] C and curly braces - question of style?

aec brat at magma.ca
Sun Aug 22 18:28:39 EST 2004


Hello,

I have recently begun what is looking like a long
and difficult journey into learning C. 

I am doing this from a book (Programming in C, Stephen Kochan)
and from a tutorial I found online. 

At this point I am working on little examples intended
for no other use but to teach. 

I am told my "style" of using curly braces {} in loops
is not generally the best way to do it.

Here is what I type for example inside a function:

        tri_number = 0;
        for (number = 1; number <= 15; ++number)
        {
                tri_number = tri_number + number;
                printf("%2i     %i\n", number, tri_number);
        }


I am told however, that if you start a "for" loop, this is clearer:


        tri_number = 0;
        for (number = 1; number <= 15; ++number) {
                        tri_number = tri_number + number;
                        printf("%2i     %i\n", number, tri_number);
        }

To me, its not clearer, but who am I to argue at this point, 
but for now, id like to continue doing it my way and worry
about actual syntax rather than style. Style isnt worth much
if your programs dont work right? 

Sure, its early in the game, and I have so much ahead of me to
learn, so why not change now to the "accepted" way? Because basically its
another little thing to remember and I have enough to keep track of,
and like I said, the first example to me is clear as a bell.

any thoughts? or should i just worry about more important things :)

-- 
Angelina Carlton


More information about the Programming mailing list