Demonstrates the goto statement - C Statement

C examples for Statement:goto

Description

Demonstrates the goto statement

Demo Code

#include <stdio.h>

int main( void ){
    int n;/*from w  w w. j a v a  2s .  c o m*/

    start:

    puts("Enter a number between 0 and 10: ");
    scanf("%d", &n);

    if (n < 0 ||n > 10 )
        goto start;
    else if (n == 0)
        goto location0;
    else if (n == 1)
        goto location1;

    location0:
    puts("You entered 0.\n");
    goto end;

    location1:
    puts("You entered 1.\n");
    goto end;

    end:
    return 0;
}

Result


Related Tutorials