for statement
The C# loop that repeats while a condition holds, with an initialiser and an update step, used when the index matters.
In more detail
for (var i = 0; i < orders.Length; i++) visits each position by number. Use foreach when you only need each item.
Related terms
- foreach — The C# loop that asks a collection for its enumerator and hands you one item at a time.
- while statement — The C# loop that repeats its body for as long as its condition stays true.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices