home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor2.zip / IFELSE.C < prev    next >
Text File  |  1989-11-10  |  931b  |  38 lines

  1.                                          /* Chapter 3 - Program 4 */
  2. /* This is an example of the if and the if-else statements */
  3.  
  4. main()
  5. {
  6. int data;
  7.  
  8.    for(data = 0;data < 10;data = data + 1) {
  9.  
  10.       if (data == 2)
  11.          printf("Data is now equal to %d\n",data);
  12.  
  13.       if (data < 5)
  14.          printf("Data is now %d, which is less than 5\n",data);
  15.       else
  16.          printf("Data is now %d, which is greater than 4\n",data);
  17.  
  18.    }  /* end of for loop */
  19. }
  20.  
  21.  
  22.  
  23. /* Result of execution
  24.  
  25. Data is now 0, which is less than 5
  26. Data is now 1, which is less than 5
  27. Data is now equal to 2
  28. Data is now 2, which is less than 5
  29. Data is now 3, which is less than 5
  30. Data is now 4, which is less than 5
  31. Data is now 5, which is greater than 4
  32. Data is now 6, which is greater than 4
  33. Data is now 7, which is greater than 4
  34. Data is now 8, which is greater than 4
  35. Data is now 9, which is greater than 4
  36.  
  37. */
  38.