Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Input/Output statements
  5. Jump statements
  6. goto statement

goto statement

Goto statement is used to branch unconditionally from one point to another within a function and unstructured way of transferring the program control form one point to another within a function.

Syntax

goto label;

goto statement is used in conjunction with an identifier labelled statement. Within the body of the function, in which goto statement is present, an identifier labelled statement with a label name, same as label name used in the goto statement should be present

Forward jump and backward jump,

There can be two or more got statements corresponding to an identifier labelled statements but there cannot be two or more identifier-labeled statement corresponding to goto statement

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

Views: 1

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments