C#

For Loop

Learn For Loop in C# with a tiny example and expected output.

For Loop is part of the C# roadmap. Use the example below and continue with the next topic.

Syntax
foreach (var n in nums) {
  Console.WriteLine(n);
}
Example
Line by line
var nums = new int[]{1,2,3};
C# line.
foreach (var n in nums) Console.WriteLine(n);
Prints a line to output.
// Expected Output: 1\n2\n3
C# line.
Real world
  • C# is used for backend APIs, desktop apps, games (Unity), and enterprise systems.
Common mistakes
  • Mixing async and blocking calls (deadlocks/timeouts).
Best practices
  • Use clear naming, prefer async/await for I/O, and keep methods small.