http://www.jindent.com |
|
Next: If-Else |
Brace style for loop statements |
Left brace { new line |
while (a < 10) { ... |
while (a < 10) { ... |
Right brace } new line |
do { ... } while (a < 10); |
do { ... } while (a < 10); |
Indent left brace { |
while·(a·<·10) ····{ ····... |
while·(a·<·10) { ... |
while·(a·<·10)·{ ... |
while·(a·<·10){ ... |
Indent right brace } |
while·(a·<·10) ····{ ····... ····} |
while·(a·<·10) { ····... } |
Indent after right brace } |
do { ... }while (a < 10); |
do { ... } while (a < 10); |
Cuddle braces of empty blocks {} |
while (condition) {} |
while (condition) { } |
Indent cuddled braces {} |
while·(condition){} |
while·(condition)·{} |
Prohibit blank lines after left brace { |
while (a < 10) { ¶ // comment with a preceding blank line callAnotherMethod(); ¶ // another comment ... } |
while (a < 10) { // comment with a preceding blank line callAnotherMethod(); ¶ // another comment ... } |
See also: | Jindent - Settings - Formatter - C / C++ - Blank Lines - Comments , Jindent - Settings - Formatter - C / C++ - Blank Lines |
If number of lines in body is at least ... then insert blank line after { |
while (a < 10) { callMethod(--a); } ¶ while (b < 10) { callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } |
while(a < 10)
looks fine,
but statement while (b < 10) {
seems to be formatted too close:
The statement head while (b < 10) {
and the first block statement
callMethodA(i);
are connected too close and could cause confusion.
while (a < 10) { callMethod(--a); } ¶ while (b < 10) { ¶ callMethodA(i); for (int i = 0; i < n; i++) { ¶ callMethodB(i); callMethodC(i); } callMethodD(i); } |
while (b < 10) {
and for (int i = 0; ...) {
seems to be much
clearer and statement while (a < 10) {
is still formatted as before.
while (a < 10) { callMethod(--a); } ¶ while (b < 10) { ¶ callMethodA(i); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } |
while (a < 10) { ¶ callMethod(--a); } ¶ while (b < 10) { ¶ callMethodA(i); for (int i = 0; i < n; i++) { ¶ callMethodB(i); callMethodC(i); } callMethodD(i); } |
infinite
.If number of lines in body is at least ... then insert blank line before } |
while (a < 10) { callMethod(--a); } ¶ while (b < 10) { ¶ callMethodA(i); for (int i = 0; i < n; i++) { ¶ callMethodB(i); callMethodC(i); ¶ } callMethodD(i); ¶ } |
Do not insert blank line before single left brace |
while (a < 10) { callMethod(--a); callMethod(--a); } // <- this right brace appears alone ¶ do { callMethodA(); callMethodB(); } while (b < 10); // <- this right brace does not appear alone |
do-while
statement does not appear alone,
it is directly followed by an >} while (b < 10)
token.
while (a < 10) { ¶ callMethod(--a); callMethod(--a); ¶ } // <- this right brace appears alone ¶ do { ¶ callMethodA(); callMethodB(); ¶ } while (b < 10); // <- this right brace does not appear alone |
do-while
statements, but for all other statements
the extra blank lines before the right braces seems to be unnecessary.
while (a < 10) { ¶ callMethod(--a); callMethod(--a); } // <- this right brace appears alone ¶ do { ¶ callMethodA(); callMethodB(); ¶ } while (b < 10); // <- this right brace does not appear alone |
} while (b < 10) {
because this is the only case a
right brace does not appear as a single brace.See also: | Jindent - Settings - Formatter - C / C++ - Braces Style - Presets |