home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list13_3.c < prev    next >
C/C++ Source or Header  |  1993-10-16  |  579b  |  36 lines

  1.  /* Demonstrates the goto statement */
  2.  
  3.  #include <stdio.h>
  4.  
  5.  main()
  6.  {
  7.      int n;
  8.  
  9.  start: ;
  10.  
  11.      puts("Enter a number between 0 and 10: ");
  12.      scanf("%d", &n);
  13.  
  14.      if ( n < 0 || n > 10 )
  15.          goto start;
  16.      else if (n == 0)
  17.          goto location0;
  18.      else if (n == 1)
  19.          goto location1;
  20.      else
  21.          goto location2;
  22.  
  23.  location0: ;
  24.      puts("You entered 0.");
  25.      goto end;
  26.  
  27.  location1: ;
  28.      puts("You entered 1.");
  29.      goto end;
  30.  
  31.  location2: ;
  32.      puts("You entered something between 2 and 10.");
  33.  
  34.  end: ;
  35.  }
  36.