for loop
By using a for loop, you can run a statement repeatedly until a specified expression evaluates to false.
- Write the following code :
using System;
namespace LearnCSharp
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
for(int i = 1; i < 11; i++)
{
sum = sum + i;
}
Console.WriteLine($"The sum of the numbers 1 to 10 is : {sum}");
}
}
}
- Run the application in the Console Window
Output in Console Window
The sum of the numbers 1 to 10 is : 55
Bob Tabor Videos
Courtesy Microsoft and Bob Tabor
NOTE - These videos are a little dated, Visual Studio 2013/2015 is being used here. But the principles are basically the same.