goto statement in c


  • This statement does not require any condition. This is unconditional control jump.
  • goto statement passes control anywhere in the program, i.e. control is transferred to another part of the program ¬≠without testing any condition.

    Syntax:

    goto label;
    

Flow Diagram:

    goto in c

    Example:

    #include <stdio.h>
    int main()
    {
       int sum=0;
       for(int i = 0; i<=10; i++){
    	sum = sum+i;
    	if(i==5){
    	   goto addition;
    	}
       }
    
       addition:
       printf("%d", sum);
    
       return 0;
    }
    

    Output:

    15