Knowledge Base

INFO: Jumping into the Middle of a For Loop Is Not Recommended

Article ID: 19972

Article Last Modified on 12/1/2003


APPLIES TO


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