When the error occurs, the function needs to return, using the goto statement to jump to the end, and then perform the corresponding release of resources, is a common way of writing, which is also the use of the GOTO statement more reasonable scheme. Through several projects, most of these programmes have been adopted.
But this has a negative effect, because all the variable definitions must be preceded by Goto, so you have to place all the variable definitions in the function's head, and the actual scope of the variable may be only a few adjacent lines, so the readability becomes weaker.
The following example uses Do{}while (0) and jumps to use the break method. Can solve this problem very well. You can define variables and use them wherever possible in a code snippet.
The source of this idea, I have not been able to remember in addition, should be seen in a book, marked, to be verified in the future.
#include <cstdio>
int main ()
{
do{
int a =;
if (a <)
{break
;
} else
{
//to do something
}
}while (0);
To does something return
0;
}