Liste des Groupes | Revenir à col misc |
On 2025-03-02, rbowman <bowman@montana.com> wrote:"For safety" I usually use the braces even if
On Sun, 2 Mar 2025 00:17:39 -0500, c186282 wrote:Even there, proper indentation saves the day:
>I pref to not put the leading bracket on the same line as the 'if' or>
'else' because then it's easier to pick out the block by eye - just
look for the '{' on the left.
I tend to put them after to make the code a little more compact. It's easy
enough to bounce between the corresponding braces in vim. The exception is
for complex for statements where the initialization, test, and increment
are on three lines.
for(i = 0;
i < 10;
i++) {
printf("%d\n", i);
}
Another thing I do to make code compact is to omit the braces if
the body of the if or for is a single line. However, I won't do this
if the next line is up two or more levels, since I want everything
to be accounted for with braces. For instance:
for(i = 0; i < 10; i++) {
printf("%d\n", i);
if((i % 2) == 0) /* Omitted braces */
printf("The preceding number is even.\n");
if((i % 3) == 0) {
printf("The preceding number is a multiple of 3.\n");
} /* Don't go up two levels without braces! */
}
Les messages affichés proviennent d'usenet.