INFO: Jumping into the Middle of a For Loop Is Not Recommended (19972)
The information in this article applies to:
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 4.0
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
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.
Modification Type: | Major | Last Reviewed: | 12/1/2003 |
---|
Keywords: | kbinfo kbLangC KB19972 |
---|
|