Iterate through a code block using for statement in C#

Beginner
Developer
Higher Education Educator
K-12 Educator
Student
.NET
Visual Studio Code

Use the for iteration statement to loop a pre-set number of times and control the iteration process.

Learning objectives

After you complete this module, you'll be able to:

  • Use the for statement to loop through a block of code
  • Modify how the .NET Runtime executes the looping logic, changing the value of the iterator, the condition and the pattern

Prerequisites

  • Experience creating simple C# applications that include console I/O and access the methods of .NET classes such as String and Random
  • Experience using Visual Studio Code to develop, build, and run C# console applications that implement arrays, if-elseif-else statements, and foreach statements
  • Experience using C# code to evaluate conditional expressions and manage variable scope inside and outside of code blocks
  • Experience using the switch-case construct to match a variable or expression against several possible outcomes