title: How to print my for loop just once? C#
body: <pre><code>internal class Invoice
  {
      public static decimal[] Total =
          {
              InvoiceLineItem.quantity[0] * InvoiceLineItem.pricePerUnit[0],
              InvoiceLineItem.quantity[1] * InvoiceLineItem.pricePerUnit[1],
              InvoiceLineItem.quantity[2] * InvoiceLineItem.pricePerUnit[2],
              InvoiceLineItem.quantity[3] * InvoiceLineItem.pricePerUnit[3],
              InvoiceLineItem.quantity[4] * InvoiceLineItem.pricePerUnit[4],
              InvoiceLineItem.quantity[5] * InvoiceLineItem.pricePerUnit[5],
          };
  
      private decimal total1;
      private decimal total2;
  
      public void Customer1()
      {
          for (var i = 0; i &lt; 3; i++)
              Console.WriteLine(String.Format("{0,-15} {1,-20} {2,-15} {3,-15} {4,-10}",
                  InvoiceLineItem.productNumber[i],
                  InvoiceLineItem.description[i],
                  InvoiceLineItem.quantity[i],
                  InvoiceLineItem.pricePerUnit[i],
                  InvoiceLineItem.Total[i]));
      }
  
      public void Customer2()
      {
          for (var k = 3; k &lt;= 5; k++)
          {
              Console.WriteLine(String.Format("{0,-15} {1,-20} {2,-15} {3,-15:C} {4,-10:C}",
                  InvoiceLineItem.productNumber[k],
                  InvoiceLineItem.description[k],
                  InvoiceLineItem.quantity[k],
                  InvoiceLineItem.pricePerUnit[k],
                  Total[k]));
          }
      }
  
      public void Customer1Total()
      {
          for (var i = 0; i &lt;= 2; i++)
          {
              total1 += Total[i];
  
              Console.WriteLine(String.Format("\nTotal of Customer 1:{0:C}", total1));
          }
      }
  }
  </code></pre>
  
  <p>I'm having a hard time printing my for loop in method <code>Customer1Total()</code> just once. I need the output <code>total1</code> to only print once but it prints 3 times adding the totals incrementally. Basically I only need the last result of this for loop but I see all of the increments. Also for extra information I'm calling the method <code>customer1total</code> in my main for it to print.</p>
  
  <p>Thank you.</p>