• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is break a normal or abrupt completion?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Federico Cardelle
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic