home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap05 / continue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-05  |  606 b   |  26 lines

  1. /* continue.c -- shows CONTINUE in loop */
  2.  
  3. main()
  4. {
  5.     int sw = 0;
  6.     char ch;
  7.     while (1) /* endless loop */
  8.     {
  9.         /* print current status */
  10.         if (sw)
  11.             printf("\nSwitch is ON\n");
  12.         else
  13.             printf("\nSwitch is OFF\n");
  14.  
  15.         printf("Do you want to quit? ");
  16.         if (ch = getche() == 'y')
  17.             break;    /* exit loop on yes */
  18.  
  19.         printf("\nDo you want to toggle the switch? ");
  20.         if (ch = getche() != 'y')
  21.             continue; /* restart loop on yes */
  22.  
  23.         sw = !sw;     /* toggle switch */
  24.         }
  25. }
  26.