Results 1 to 4 of 4

Thread: [RESOLVED] What is a " label "?

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Resolved [RESOLVED] What is a " label "?

    Hi ….

    Can you explain what is a label, which is used with loops, with the following example?

    I found it from a book. But still can't understand this code.


    boolean found = false;

    outer: for(int row=0; row<10; row++)

    {

    inner: for(int col=0; col<10; col++)

    { // some code which may change found to true

    if(found)
    {
    break outer; // jumps to outer loop

    }}}

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: What is a " label "?

    A label allows you to break out of a certain loop. If you have three loops nested and you want to break out of the outermost loop, then how is the compiler suppose to know what loop to break out of?

    A normal break statement simply looks like this:

    Code:
    break;

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: What is a " label "?

    Quote Originally Posted by System_Error
    A label allows you to break out of a certain loop. If you have three loops nested and you want to break out of the outermost loop, then how is the compiler suppose to know what loop to break out of?

    A normal break statement simply looks like this:

    Code:
    break;
    That's very correct.
    But in addition: The label is the physical address of command, you can consider it "a Name" for the following line.
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: What is a " label "?

    Thanks for your comments.

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