}
}
}
Each time a diagonal element of the matrix is reached, the rest of that row is skipped by continuing with the
outer loop that iterates over the columns.
10.9. return
A return statement terminates execution of a method and returns to the invoker. If the method returns no
value, a simple return statement will do:
return;
If the method has a return type, the return must include an expression of a type that could be assigned to
the return type. For example, if a method returns double, a return could have an expression that was a
double, float, or integer:
protected double nonNegative(double val) {
if (val < 0)
return 0; // an int constant
else
return val; // a double
}
A return can also be used to exit a constructor. Since constructors do not specify a return type, return is
used without a value. Constructors are invoked as part of the new process that, in the end, returns a reference
to a new object, but each constructor plays only a part of that role; no constructor "returns" the final reference.
10.10. What, No goto?
The Java programming language has no goto construct that transfers control to an arbitrary statement,
although goto is common in languages to which the language is related.[2] The primary uses for goto in
such languages have other solutions:
[2] Although not used goto is a reserved keyword, as is const. The reason they are reserved
is mostly historical: Both of these come from strongly related programming languages, like C
and C++, and reserving them helped compilers advise programmers clearly that they were
using something that didn't make sense. Occasionally, suggestions are made for how const
might be used in the Java programming language.
Controlling outer loops from within nested loops. Use labeled break and continue statements to
meet this need.
•
Skipping the rest of a block of code that is not in a loop when an answer or error is found. Use a
labeled break.