CSharp examples for Language Basics:for
Summing integers with the for statement.
using System;/*from ww w .j a va2 s.c o m*/ class Sum { static void Main() { int total = 0; // initialize total // total even integers from 2 through 20 for (int number = 2; number <= 20; number += 2) { total += number; } Console.WriteLine($"Sum is {total}"); // display results } }