goto
The goto statement in C is a control flow statement that is used to transfer control to a labeled statement in the same function. It is often used to break out of nested loops or to skip over certain code blocks.
The goto statement should be used with caution, as it can make code more difficult to understand and maintain. It is generally considered a poor programming practice, and there are often better alternatives to using goto.
Here is the basic syntax of the goto statement in C:
goto label;
...
label:
// code block to be executed
In the goto statement, the label is a identifier that represents a labeled statement in the same function. When the goto statement is executed, control is transferred to the labeled statement.
Here is an example of using the goto statement to break out of a nested loop in a C program:
#include <stdio.h>
int main()
{
int i, j;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
if (i == 5 && j == 5) {
goto end;
}
printf("%d, %d\n", i, j);
}
}
end:
printf("Done\n");
return 0;
}