Giving name to a loop

前端 未结 6 1775
北荒
北荒 2020-12-06 05:33

While browsing questions and answers in this forum i found a piece of code were names were given to loops in order to use them for break. Like

nameofloop:
          


        
6条回答
  •  暖寄归人
    2020-12-06 05:49

    Officially, I believe this is called a "labeled break". It's useful for breaking out of nested loops, such as:

    found:
        for (int i = 0; i < 100; i++)
            for (int j = 0; j < 100; i++)
                if ( /* Some condition is met */)
                    break found;
    

    I don't think it's useful for anything else.

提交回复
热议问题