topical media & game development

talk show tell print

basic-program-code-03-Ex3-07.c

? / basic-program-code-03-Ex3-07.c


  // Ex3_07.cpp
  // Creating a loop with an if and a goto
  include <iostream>
  
  using std::cin;
  using std::cout;
  using std::endl;
  
  int main()
  {
     int i = 0, sum = 0;
     const int max = 10;
  
     i = 1;
  loop:
     sum += i;             // Add current value of i to sum
     if(++i <= max)
        goto loop;         // Go back to loop until i = 11
  
     cout << endl
          << "sum = " << sum
          << endl
          << "i = " << i
          << endl;
     return 0;
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.