xxxxxxxxxx
for (initializer; condition; iterator)
body
//Example :
for (int i = 0; i < 5; i++)
{
Console.WriteLine(i);
}
xxxxxxxxxx
for (int i = 0; i < 5; i++)
{
Console.WriteLine(i);
}
______________OUTPUT____________
0
1
2
3
4
xxxxxxxxxx
//int i = 0 -- Making variable i
//i <=10 -- Making a condition for the loop to keep going
//i++ -- Increasing i by 1
for(int i = 0; i <= 10; i++)
{
Console.Write(i+1);
}
/*
Output:
12345678910
*/
xxxxxxxxxx
for (int i = 0; i < 5; i++)
{
if (i >= 4)
{
break;
}
Console.WriteLine(i);
}
xxxxxxxxxx
using System;
namespace Loop
{
class ForLoop
{
public static void Main(string[] args)
{
for (int i=0; i<=10; i++)
{
Console.WriteLine("C# For Loop: Iteration {0}", i);
}
}
}
}