Results 1 to 3 of 3

Thread: labeled continue and break

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004

    labeled continue and break

    I am a beginner in Java so maybe I got this wrong, but do the labeled continue and break statements act like the goto of so many other programming languages?

    If it does, should we ever use these labeled forms?
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    The continue and break statements are normally refered to as transfer statments with the others being control if, if else and iteration for, while. The break statement serves to break loops and continue statements serve to continue execution by passing the point after the continue and going back to the begining of the loop. Goto should never really be used in any modern programming lauguage since it leads to what some people call Spaghetti code.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Labeled break and continue serve to break out of nested loops, like in
    Code:
    outer:
    for(int i = 0; i < 100; ++i) {
      for(int j = 0; j <= i; ++j) {
        break outer;
      }
    }
    Whether it makes sense is open for debate.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width