일단 대부분의 경우 쓰지 말라고 가르치고,

아예 존재 자체를 안 가르치는 교재도 상당히 많으나,


실제로는 리눅스 커널에서도 상당히 많이 씀

어떤 상황에서 쓰느냐,

함수 내에서 예외처리할 때 조건 통과를 못하는 모든 경우에 대해서

같은 에러 코드를 띄우고 비정상 종료 처리를 똑같이 해야될 때 코드 재사용을 하기 위해서 사용한다.


T func(...args...)

{

if(...)

{

if(...)

else

goto error;

}

else

   goto error;


error:

printf("error in func!");

return -1;

}


이런 식으로


2중 포문 탈출하는건 다들 알테니 그렇다 치고,


결론으로 말하자면, 얼마전에 본 책에서 정리를 잘 해준 것 같은데


SAMS Teach Yourself C++ for Linux in 21 Days, Jesse Liberty, David B. Horvath, p183

"To avoid the use of goto, more sophisticated, tightly controlled looping commands have been introduced:

for, while, and do...while. Using these commands makes programs that are more easily understood, and

goto is generally avoided, but one might argue that THE CASE HAS BEEN A BIT OVERSTATED. Like any

too carefully used and in the right hands, goto can be a useful construct, and thd ANSI committee decided

to keep it in the language because it has its legitimate uses. But as they say, "Kids, don't try this at home!"."


C++에서도 도입이 된 것을 보면 확실히 goto는 존재 이유가 분명하다는 것

다만, 왜 언제 어떻게 쓰는지 알기 전에는 쓰지 말라는 것