home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / alb_c10 / chap_05 / ch05_17.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-26  |  2.3 KB  |  76 lines

  1. /*********************************************************************
  2. *  CH05_17.C                                  L'instruction goto   *
  3. *                                                                    *
  4. *  Gordon Dodrill de Coronado Entreprises     12501 Coronado Ave NE  *
  5. *                         Albuquerque, New Mexico 87122 *
  6. * a Θcrit ce programme dans son excellent C TUTORIAL le 10 nov 1989  *
  7. * au profit de ses ΘlΦves qui Θtudient le C pour tenter de les guΘrir*
  8. * de l'emploi du goto! J'ai pensΘ qu'il Θtait inutile de traduire.   *
  9. *********************************************************************/
  10.  
  11. #include<stdio.h>
  12.  
  13. main( void)
  14. {
  15. int dog,cat,pig;
  16.  
  17.    goto real_start;
  18.  
  19.    some_where:
  20.    printf("This is another line of the mess.\n");
  21.    goto stop_it;
  22.  
  23. /* the following section is the only section with a useable goto */
  24.    real_start:
  25.    for(dog = 1;dog < 6;dog = dog + 1) {
  26.       for(cat = 1;cat < 6;cat = cat + 1) {
  27.          for(pig = 1;pig < 4;pig = pig + 1) {
  28.             printf("Dog = %d  Cat = %d  Pig = %d\n",dog,cat,pig);
  29.             if ((dog + cat + pig) > 8 ) goto enough;
  30.          };
  31.       };
  32.    };
  33.    enough: printf("Those are enough animals for now.\n");
  34. /* this is the end of the section with a useable goto statement */
  35.  
  36.    printf("\nThis is the first line out of the spaghetti code.\n");
  37.    goto there;
  38.  
  39.    where:
  40.    printf("This is the third line of spaghetti.\n");
  41.    goto some_where;
  42.  
  43.    there:
  44.    printf("This is the second line of the spaghetti code.\n");
  45.    goto where;
  46.  
  47.    stop_it:
  48.    printf("This is the last line of this mess.\n");
  49.  
  50. }
  51.  
  52. /* Result of execution
  53.  
  54. Dog = 1  Cat = 1  Pig = 1
  55. Dog = 1  Cat = 1  Pig = 2
  56. Dog = 1  Cat = 1  Pig = 3
  57. Dog = 1  Cat = 2  Pig = 1
  58. Dog = 1  Cat = 2  Pig = 2
  59. Dog = 1  Cat = 2  Pig = 3
  60. Dog = 1  Cat = 3  Pig = 1
  61. Dog = 1  Cat = 3  Pig = 2
  62. Dog = 1  Cat = 3  Pig = 3
  63. Dog = 1  Cat = 4  Pig = 1
  64. Dog = 1  Cat = 4  Pig = 2
  65. Dog = 1  Cat = 4  Pig = 3
  66. Dog = 1  Cat = 5  Pig = 1
  67. Dog = 1  Cat = 5  Pig = 2
  68. Dog = 1  Cat = 5  Pig = 3
  69. Those are enough animals for now.
  70.  
  71. This is the first line out of the spaghetti code.
  72. This is the second line of the spaghetti code.
  73. This is the third line of spaghetti.
  74. This is another line of the mess.
  75. This is the last line of this mess.                    */
  76.