| Author |
Is break a normal or abrupt completion?
|
Federico Cardelle
Greenhorn
Joined: Jul 26, 2011
Posts: 26
|
|
Hi. I am reading the chapter 12 of the Java Language Specification, about statements http://java.sun.com/docs/books/jls/third_edition/html/statements.html and it says
An abrupt completion always has an associated reason, which is one of the following:
A break with no label
A break with a given label
A continue with no label
A continue with a given label
A return with no value
A return with a given value
A throw with a given value, including exceptions thrown by the Java virtual machine
but later, talking about the for statement (14.14.1.2), it says
If the Expression is not present, then the only way a for statement can complete normally is by use of a break statement.
Is this incoherent or am I misunderstanding something?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
I think you are interpreting the words too much.
It looks like you think that "abrupt completion" means "abnormal completion", as opposed to the words "complete normally" that you read about the for-statement. But I think that "abrupt completion" does not really mean "abnormal completion", and the statement that describes the for-statement doesn't directly have anything to do with the first description about abrupt completion. The statements are not contradicting each other, they are just talking about different things.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Federico Cardelle
Greenhorn
Joined: Jul 26, 2011
Posts: 26
|
|
But...
14.1 Normal and Abrupt Completion of Statements
If all the steps are carried out as described, with no indication of abrupt completion, the statement is said to complete normally. (...)
There is also a section about the break statement, but tt is also obscure to me...
14.15 The break Statement
(...)
A break statement with no label attempts to transfer control to the innermost enclosing switch, while, do, or for statement of the immediately enclosing method or initializer block; this statement, which is called the break target, then immediately completes normally.
To be precise, a break statement with no label always completes abruptly, the reason being a break with no label. If no switch, while, do, or for statement in the immediately enclosing method, constructor or initializer encloses the break statement, a compile-time error occurs.
After rereading the chapter, I think that the break statement makes the body of the for statement (what is in parenthesis after the for(...) line ) complete abruptly, giving control to the for statement (or switch, while, do), which completes normally. Maybe an English native speaker understands it more clearly
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16684
|
|
Federico Cardelle wrote:Maybe an English native speaker understands it more clearly
Maybe the keyword here is "speaker". The Java Language Specification, like all specifications, is written in a form of legalese. It can hardly be considered as written in the spoken form of english -- unless of course, you are a lawyer.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
|
If you're trying to learn this because you want to do a certification exam, then don't worry about the exact definitions of words like "abrupt completion" and "normal completion" too much. You are not going to get questions on the exam that uses these terms. These are also not terms that a Java developer uses everyday to reason about code.
|
 |
 |
|
|
subject: Is break a normal or abrupt completion?
|
|
|