One of the basic concepts in programming is understanding loops. In this article, we will explore a simple C# program that uses a for
loop to print numbers from 1 to 100. This is a fundamental exercise to help beginners understand how loops work in C#.
Code Example
Here is a basic program written in C# to print numbers from 1 to 100:
Example 1:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Program { static void Main(string[] args) { for(int i=1;i<=100;i++) { Console.WriteLine(i); } Console.ReadKey(); } } |
Output:
Example 2:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Program { static void Main(string[] args) { for(int i=1;i<=100;i++) { Console.Write(i+" "); } Console.ReadKey(); } } |
Output: