Is it possible to use the break
function to exit several nested for
loops? If so, how would you go about doing this? Can you also control how many loops the break exits?
相关问题
- Is there a limit to how many levels you can nest i
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Although this answear was already presented, i think a good approach is to do the following:
from msdn.
I know this is old post . But I would suggest a bit logical and simpler answer.
I do think a
goto
is valid in this circumstance:To simulate a
break
/continue
, you'd want:Break
Continue
Another approach to breaking out of a nested loop is to factor out both loops into a separate function, and
return
from that function when you want to exit.Of course, this brings up the other argument of whether you should ever explicitly
return
from a function anywhere other than at the end.