Day 4 of 30-Day .NET Challenge: For Loops
Published in
3 min readMar 23, 2024
Introduction
Welcome to this module Day 4 of 30-Day .NET Challenge: For Loops
, where let's dive into the world of for
statements. Explore how to write for
statements that iterate a set number of times.
Learning Objectives
- Utilize the
for
statement to iterate through a set of code.
Prerequisites for Developers
- Proficiency with the
foreach
iteration statement. - Familiarity with working with variables.
Getting Started
What is the for statement?
The for
statement allows you to iterate through a code block a fixed number of times, providing precise control over the iteration process.
Basic For Loop Example
To begin, create a static class file called “ForLoop.cs
” within the console application. Insert the provided code snippet into this file.
/// <summary>
/// Outputs
/// 0
/// 1
/// 2
/// 3
/// 4
/// 5
/// 6
/// 7
/// 8
/// 9
/// </summary>
public static void ForLoopExample()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
}
}