User User - 6 months ago 34
C# Question

Writing Loops with multiplication C#

I am having an issue with trying to write a loop that requires me to multiply. What I am trying to do is write a loop that outputs:

i*3 for i = 10 t i = 4000


I tried using a counter method but it seems I am doing something wrong so i tried to fix it an did this

int i = 10;
for (i = 10; i < 4000; )
{
int r = i * 3;
Console.WriteLine(r);


but the number 30 goes into an infinite loop. Any help is appreciated, I am trying to do this for fun so I am self learning. Thanks again!

Answer Source

You're almost there (based on your comments)

int i = 10;
while (i < 4000) 
{
    int r = i * 3;
    Console.WriteLine(r);
    i = r;
}

If it has to be a for loop:

for (int i = 10; i < 4000; ) 
{
    int r = i * 3;
    Console.WriteLine(r);
    i = r;
}