Java Reference
In-Depth Information
if (...)
{ System.out.println(x); }
Conventions for indenting an if-else statement
Our convention is a simple extension of if-statement convention, e.g.:
if (...) {
System.out.println(x);
System.out.println(y);
} else {
System.out.println(z);
}
13.2.2
Indenting assertions
An assertion is a relation about variables that is enclosed in braces { and } and
written as a comment. It appears at the same level of indentation as the statement
that precedes or follow it. Its appearance in a program asserts that it is true when
execution reaches the position where it occurs. This is illustrated in the follow-
ing program segment, which has a precondition and a postcondition:
// { x = A and y=B (for some values A and B) }
int t= x;
x= y;
y= t;
// { x = B and y = A }
13.2.3
Indenting loops
Our conventions are similar to those for an if-statement:
// invariant: …
while (...) {
System.out.println(x);
System.out.println(y);
}
// invariant: …
for (i= 0; i != n; i= i + 1) {
System.out.print(i);
System.out.println( " " + (i * i));
}
Convention for loop invariants
A loop invariant is a relation whose truth is maintained by execution of the
repetend of the loop (under the condition that the loop invariant is initially true).
Search WWH ::




Custom Search