According to the java book I am reading right now, you can use labels with the following types of statements:
I understand how to use them with constructs that have curly braces but what are some useful examples of using them with the other kind of statements, like expressions, assignments, return statements and throw statements?
How do you use the label statement in Java?
It isn't a statement. It is an optional attribute of an executable statement.
According to the java book I am reading right now, you can use labels with the following types of statements ...
Your book is wrong. According to the Java Language Specification #14.7, any statement can have a label. However they can only be referenced by break
statements, which in turn can only appear inside switch, while, do,
or for
statements (#14.15), or by continue
statements, which in turn can only appear inside while, do,
or for
statements (#14.15).
what are some useful examples of using them with the other kind of statements, like expressions, assignments, return statements and throw statements?
There aren't any.