Cycles C#

Mar 12, 2023 00:00 · 77 words · 1 minute read

The use of loops in C# is briefly described in the article.

for (int i = 0; i < 9; i++)
{
    if (i == 5)
        break;
        //continue;
    Console.Write(i);
}

int i = 60;
while (i > 0)
{
    Console.WriteLine(
	Convert.ToString(i, 2).PadLeft(8, '0'));
    i--;
}

i = -1;
do
{
    Console.Write(i);
    i--;
} while (i > 0);

int[] numbers = 
new int[] { 1, 2, 3, 4, 5 };
foreach (int i in numbers)
{
    Console.Write(i);
}