goto statement in c - goto Statement in C Program



 goto Statement in C Program

Learn c - c tutorial - goto Statement in C Program(Repeat) - c examples - c programs

goto Statement in C Program

  • goto Statement is a programming language and it performs a one-way transfer.
  • Jumped-to locations are generally identified using labels, though some languages use line numbers at the machine code level.
  • A goto is a form of branch or jump statement.
 goto Statement in C Program

Learn c - c tutorial - goto Statement in C Program - c examples - c programs

a) goto Statement in C Program (Repeat)

Sample Code

#include <stdio.h>
int main()
{
    int number;
    number=1;
repeat:
    printf("%d\n",number);
    number++;
    if(number<=10)
        goto repeat;
    return 0;
}

Output

1
2
3
4
5
6
7
8
9
10

b) goto Statement in C Program (Quit)

 goto Statement in C Program

Learn C - C tutorial - goto Statement in C Program - C examples - C programs

Sample Code

#include <stdio.h>
int main()
{
    int number=29;
    printf("Integer: %d\n",number);
    scanf("%d",& number);
    if(number< 0)
        goto QUIT;
    printf("Entered number is: %d\n",number);
QUIT:
    printf("BYE BYE!!!\n");
    return 0;
}

Output

Integer: 29
Entered number is: 29
BYE BYE!!!

View More Quick Examples


Related Searches to goto statement in c - goto Statement in C Program