Control Structures in Java

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

*The body of a method in Java consists of a block which encloses a sequence of statements in braces.
 
*So far we have seen (more or less) following statements:


NameSyntax and Examples

Declaration

Modifier Type Identifier Initializer ;

int i;

final double pi = 3.14159265358979323846;

Expression StatementExpression ;

this.gallons = this.gallons + gallons;

log = new FuelLog(initialMileage);

log.fillUp(mileage, gallons);

Return Statementreturn Expression ;

return (mileage - initialMileage) / gallons;

return;

Empty Statement;

Block Statement

{ Statement1 Statement2 ... }

{ int i; i = 1; }

{}

{;}

{ int i; { int j = i; int i = j; } int j; }


 

*So far all statements were executed just once per invocation of the method exactly in the order given. There were no repetitions nor selections of statements.
 
*Statements that support repetition and conditional execution are called control statements or control structures.
 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002