goto
is an unstructured control flow statement. It makes code less readable and maintainable. Structured control flow statements such
as if
, for
, while
, continue
or break
should be used instead.
Noncompliant code example
int i = 0;
loop:
printf("i = %d\n", i);
i++;
if (i < 10){
goto loop; // Noncompliant
}
Compliant solution
for (int i = 0; i < 10; i++) {
printf("i = %d\n", i);
}