Java Reference
In-Depth Information
185
S YNTAX 5.2 Block Statement
{
statement 1
statement 2
. . .
}
Example:
{
double newBalance = balance - amount;
balance = newBalance;
}
Purpose:
To group several statements together to form a single statement
S ELF C HECK
1.
Why did we use the condition amount = balance and not
amount < balance in the example for the if/else statement?
2.
What is logically wrong with the statement
if (amount <= balance)
newBalance = balance - amount; balance =
newBalance;
and how do you fix it?
Q UALITY T IP 5.1: Brace Layout
The compiler doesn't care where you place braces, but we strongly recommend
that you follow a simple rule: Line up { and } .
if (amount <= balance)
{
double newBalance = balance - amount;
balance = newBalance;
Search WWH ::




Custom Search