Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Statements

Simple Statements

Each line should contain at most one statement. All simple statements should end with a semicolon (;).

// Good
count++;
a = b;

// Bad: Multiple statements on one line
count++; a = b;

return Statement

A return statement with a value should not use parentheses unless they make the return value more obvious in some way. Example:

return;

return collection.size();

return (size > 0 ? size : defaultSize);

Compound Statements

Compound statements are lists of statements enclosed inside of braces.

  • The enclosed statements should be indented one more level than the compound statement.

  • The opening brace should be at the end of the line that begins the compound statement; the closing brace should begin a line and be indented to the beginning of the compound statement.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint