public class While {

  // sumTo : Takes a number (an int) and evaluates to the sum
  // of numbers up to that one

  public static void main(String[] args) {
    System.out.println(sumTo(10));
    System.out.println(sumTo(4));
  }
  public static int sumTo(int top) {
    int total = 0;
    int current = 1;
    while(current <= top) {
      total = total + current;
      current = current + 1;
    }
    return total;
  }
  public static int sumTo(int top) {
    int total = 0;
    while(top > 0) {
      total = total + top;
      top = top - 1;
    }
    return total;
  }
  public static int sumTo(int top) {
    int total = 0;
    int current = 0;
    while(current <= top) {
      total = total + current;
      current = current + 1;
    }
    return total;
  }
  public static int sumTo(int top) {
    int total = top;
    while(top > 0) {
      top = top - 1;
      total = total + top;
    }
    return total;
  }


*/



    // For this implementation:

  public static int sumTo(int top) {
    int total = 0;
    while(top > 0) {
      total = total + top;
      top = top - 1;
    }
    return total;
  }

    // for the input 6, what are the values at the beginning and end of the
    // first three times through the loop (_iterations_)?
    //      BEFORE                  AFTER

    // A:
    //  1: total = 0, top = 6;   total = 6, top = 5
    //  2: total = 6, top = 5;   total = 11, top = 4
    //  3: total = 11, top = 4;  total = 15, top = 3


    // B:
    //  1: total = 0, top = 0;   total = 0, top = 1
    //  2: total = 0, top = 1;   total = 1, top = 2
    //  3: total = 3, top = 2;   total = 5, top = 3

    // C:
    //  1: total = 6, top = 6;   total = 11, top = 5
    //  2: total = 11, top = 5;  total = 15, top = 4
    //  3: total = 15, top = 4;  total = 18, top = 3

    // D:
    //  1: total = 0, top = 6;   total = 6, top = 6
    //  2: total = 5, top = 5;   total = 11, top = 5
    //  3: total = 11, top = 4;  total = 15, top = 4


}
