Hamed Najafi

Exercise 1 C# – For Loops

In this Example I am going to write a code to get a number from client and sum up from 1 to the which number client entered. Here’s how I did it.

int i;
int n = 0;
//Client Enters a number
Console.WriteLine("Enter Your Number:");
//Read the Clients number and assign it to variable called "number"
int number =Int32.Parse(Console.ReadLine());
//Now the game starts
for (i = 1; i < number ; i++) {
n = n + i ;


Here’s the result: I entered 20 to sum up.