有限循环

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int i;
  5. int sum = 0;
  6. for (i = 0; i <= 100; i++)
  7. {
  8. sum += i;
  9. }
  10. printf("sum = %d\n", sum);
  11. return 0;
  12. }

无限循环

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int i = 1;
  5. int sum = 0;
  6. for (;;)
  7. {
  8. sum += i;
  9. printf("sum = %d\n", sum);
  10. }
  11. return 0;
  12. }