C – goto statement

goto statement in c allows the user in the program to jump the execution to the labeled statement inside the function. The label (tag) is used to spot the jump statement.

NOTE: Remember the use of goto is avoided in programming language because it makes difficult to trace the control flow of a program, making the program hard to understand and hard to modify.

goto statement Flowchart:

goto statement in C
goto statement in C

Syntax of goto statement:

goto label;
....
....
label: statement; //label to jump

Example of goto statement in C Program.

#include <stdio.h>

void main()
{
  int i = 1;

  label: do {
  if (i == 8)
  {
     //skip the iteration
      i++;
      goto label;
  }

  printf("Value of i: %d\n", i);
  i++;
  } while (i <= 10);
}

The output of continue statement.

Value of i: 1
Value of i: 2
Value of i: 3
Value of i: 4
Value of i: 5
Value of i: 6
Value of i: 7
Value of i: 9
Value of i: 10