INFO: Jumping into the Middle of a For Loop Is Not Recommended
Article ID: 19972
Article Last Modified on 12/1/2003
APPLIES TO
- Microsoft Visual C++ 1.0 Professional Edition
- Microsoft Visual C++ 1.5 Professional Edition
- Microsoft Visual C++ 2.0 Professional Edition
- Microsoft Visual C++ 4.0 Standard Edition
- Microsoft Visual C++ 5.0 Enterprise Edition
- Microsoft Visual C++ 6.0 Enterprise Edition
- Microsoft Visual C++ 5.0 Professional Edition
- Microsoft Visual C++ 6.0 Professional Edition
- Microsoft Visual C++ 6.0 Standard Edition
This article was previously published under Q19972
SUMMARY
In Microsoft C and in Microsoft C/C++, the goto statement and its
corresponding label must be part of the same function; no other
restrictions apply. However, because different compilers optimize for
loops and allocate stack space for automatic variables in various
ways, using a goto statement to transfer flow-of-control into the
middle of a for loop is not portable and is considered unsafe.
The most common use for the goto statement in structured programming
involves error handling. In these cases, the goto statement usually
leads out of a deeply nested for loop.
Keywords: kbinfo kblangc KB19972