Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is ROW_LOOP?  RSS feed

 
Ryan Sellers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm studying for my OCA certification, using the Sybex 1z0-808 study guide, and I came across a question with something I've never seen before, and almost nothing in the internet about it.

One of the end of chapter questions has a bit like "ROW_LOOP:", and I have no idea what that means. It doesn't even look like java.




So...what is this? the book never explains this bit of code, and I can't find anything on the internet to explain it either.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ROW_LOOP: is a label for the continue statement to use. See the tutorial: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
 
Ryan Sellers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:ROW_LOOP: is a label for the continue statement to use. See the tutorial: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html


Ok, thanks so much! I've only been working with java for about two years now, so I haven't seen all there is to see. I've never actually seen a continue statement used "in the wild", though I was aware of their existence. I was wholly unaware of labelled continue statements. The book and all other references seem to suggest that continue statements are rarely used, does the same hold for labeled continue statements?
 
Campbell Ritchie
Marshal
Posts: 55678
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A lot of people, myself included, don't like that construct because it is too similar to a goto. There are (I think) four kinds of labelled statement:-
  • 1: An assert statement which may be followed by a label (I think) which is printed as well as the exception if the assertion is false. Forget about that for the time being.
  • 2: After case as in switch‑case. You have doubtless used hundreds of such labels and hardly noticed it.
  • 3: After break. You terminate the current loop and transfer control to the label, which shoul‍d be before the outer loop. If I remember correctly, the outer loop is “broken”, and control then passes to the end of the loop, but I am not certain. The outer loop does not run again, I think, but not certain.
  • 4: After continue. You terminate the current loop and transfer control to the label, which shoul‍d be before the outer loop. If I remember correctly, the outer loop is not “broken”, and control then passes to the beginning of the loop, but I am not certain. The outer loop will continue running (which is why the keyword is continue) from its next iteration.
  • I think the Java™ Tutorials section about labelled control statements is difficult to read.

    Labels date back to C in 1972, and probably a lot before that. I think the continue keywords was introduced because goto is never used, and labelled control statements allow control to pass backwards in the code, which is less likely to create spaghetti code than goto myLabel;, which can pass control forwards.

    I think your code will summate the first fields in each row where both row and column are odd numbers. Once an even number is encountered the control moves to the next loop.
     
    Knute Snortum
    Sheriff
    Posts: 4070
    112
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Continue statements going to a label are rare.  Some people consider them bad style and avoid them at all costs.

    A continue statement only applies to the "closest" loop, so in this code:

    If you wanted to continue to some other loop, you need a label.
     
    L Hasan
    Greenhorn
    Posts: 24
    4
    Eclipse IDE Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    I am also studying for the OCA Java 8 exam, from the same book as you and have literally just finished the chapter containing info on Labels.

    It can be found on page 87/88, gives a fairly short, but concise summary and deals with them more in the sections following that cover Break and Continue. The book does say something about not being covered in the exam, but I couldn't tell if that meant Labels as a whole, or in the context of Control/Block structures.

    Hope that helps,

    L.
     
    Knute Snortum
    Sheriff
    Posts: 4070
    112
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Welcome to the Ranch, L Hasan!  And thanks for your contribution.
     
    L Hasan
    Greenhorn
    Posts: 24
    4
    Eclipse IDE Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks! Got to start somewhere I guess!

    L.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!