title: how can i return and increment in the same for-loop in java
body: <p>I've encountered the problem where if I increment the for-loop my program crashes after the for-loop has been executed, but if I don't increment the for-loop and use a return statement to return <code>projectedSales</code> my program continues to run.</p>
  
  <p>However, if I don't increase then <code>projectedSales</code> just outputs the last number for <code>projectedSales1</code> without adding it to <code>projectedSales</code>.</p>
  
  <p>So my question here is, how can i increment the for-loop so that <code>projectedSales  = projectedSales + projectedSales1</code> continues to collect data and returns <code>projectedSales</code> at the end?</p>
  
  <pre><code>    Scanner input = new Scanner(System.in);
      double projectedRevenue2025 = 0;
      double projectedSales1 = 0;
      double projectedSales = 0;
      double baseSales;
      double growthRate;
      double numberOfYears;
      int [] productPrice = {1825, 670, 880, 1910, 485};
  
      DecimalFormat df = new DecimalFormat("#");
  
      for (double i = 0; i &lt;= 4;) {
          System.out.println("What is the base sale?");
          baseSales = input.nextDouble();
  
          System.out.println("What is the growth rate?");
          growthRate = input.nextDouble();
  
          System.out.println("What is the expected number of years?");
          numberOfYears = input.nextDouble();
  
          //calculates the projected sales of the upcoming years
          projectedSales1 = baseSales * (Math.pow((1 + (growthRate / 100)), numberOfYears));
  
          System.out.println("The projected sale is: " + df.format(projectedSales1));
          //this should store data from projectedSales1 into projectedSales and add it to the previous data
          projectedSales = projectedSales + projectedSales1;
  
          projectedRevenue2025 = (projectedSales1 * productPrice[(int) i]) + projectedRevenue2025;
          System.out.println("The total projected revenue is: $" + df.format(projectedRevenue2025)); //prints total projected revenue
          return projectedSales;
      } //close for-loop      
  
      input.close();
  
      return projectedSales;
  } //closes projSales
  </code></pre>
  
  <p>PS. the return statement after <code>input.close()</code> is to return <code>projectedSales</code> to the main method</p>
  
  <p>EDIT: I was supposed to hard code this program. My issue was with the input statements in the beginning of the loop. Thank you all, I really appreciate y'all taking the time to help.</p>