You need to keep track of how many numbers you've printed out and then break out of the loop once you have enough:
int counter = 0;
for (int i = 200; i < 2000; i++)
{
if ((i % num1 == 0) && (i % num2 ==0))
{
Console.WriteLine(i);
counter++;
if(counter == 20)
break;
}
}
Or you can use a for
loop with two conditions:
for (int i = 200, j= 0; i < 2000 && j < 20; i++)
{
if ((i % num1 == 0) && (i % num2 ==0))
{
Console.WriteLine(i);
j++;
}
}