naor ohayon naor ohayon - 3 months ago 11
C# Question

How can I combine those two loops into one?

I want to combine this two loops to one:

for (int i = 7; i <=100; i+=10)
{
Console.WriteLine(i);
}

for (int i = 0; i < 100; i+=7)
{
Console.WriteLine(i);
}

Answer

I assume this is what you're trying to do

for (int i = 0; i<= 100; i++)
{
    if (i%7==0 || i%10==7) 
       Console.WriteLine(i);
}