Fifth International World Wide Web Conference
Control Constructs
- Java supports a complete set of control constructs:
- if-then-else
switch
while loops (both top test and bottom test)
- for-loops
- try-catch blocks (for exception handling)
break used to exit from a switch or loop statement
continue used within looping constructs to advance to the
next iteration
- Both
break and
continue may optionally indicate which construct they apply to
(useful in nested constructs)
- There is no
goto statement in Java
- The
return statement is used to exit a method
- No return value is specified for
void methods
- Otherwise, expression must be of same type as method return type
Java - An Introductory Language Tutorial
(E.A.Johnson)