Jindent - Java Source Code Formatter http://www.jindent.com
 



title
5.6.2.4 Braces/Parentheses Insertion

To improve readability of source code it can be helpful to insert parentheses and braces into certain statements and conditions without really changing its functionality.
These parentheses and braces are only necessary to clarify the order of execution (i.e. in conditions) or to point up the scope levels of statements (i.e. in if-else statements).



title
5.6.2.4.1 Insertion Of Braces/Parentheses

For statements

For statements

Inserts braces into for statements which just contain of a single statement instead of a whole block:

Before inserting braces:

for (int i = 0; i < n; i++)             
    cout << i;                          


After inserting braces:

for (int i = 0; i < n; i++) {           
    cout << i;                          
}                                       



While statements

While statements

Inserts braces into while statements which just contain of a single statement instead of a whole block:

Before inserting braces:

while (++i < n)                         
    cout << i;                          


After inserting braces:

while (++i < n) {                       
    cout << i;                          
}                                       



Do-while statements

Do-while statements

Inserts braces into do-while statements which just contain of a single statement instead of a whole block:

Before inserting braces:

do                                      
    
cout << i;                          
while (++i < n)                         


After inserting braces:

do {                                    
    cout << i;                          
while (++i < n);                      



If-else statements

If-else statements

Inserts braces into if-else statements which just contain of a single statement instead of a whole block:

Before inserting braces:

if (i == 0)                             
    callMethodA();                      
                                        
if (i < n)                              
    cout << i;                          
else                                    
    
System.out.println(n);              


After inserting braces:

if (i == 0) {                           
    callMethodA();                      
}                                       
                                        
if (i < n) {                            
    cout << i;                          
else {                                
    
System.out.println(n);              
}                                       



Conditions

Conditions

Inserts parentheses into conditions to improve its readabilty.


Before inserting parentheses:

int x = a < 100 0;                
                                        
if (x == || 1000 > a && a > 10) {     
    cout << a;                          
}                                       


After inserting parentheses:

int x = (a < 100) ? 0;              
                                        
if ((x == 0) || ((1000 > a) && (a > 10))) {
    cout << a;                          
}