Build error: Name 'x' does not exist in current context

Asked

Viewed 101 times

2

I’m trying to do this exercise in C#, but every time I try to compile it points out the error:

The name i does not exist in the current context

Someone knows how to fix this?

int N, a, b;

N = int.Parse(Console.ReadLine());
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());

for(int i = a; i <= b; i++);
{
    if(i % N == 0)
    {
        Console.WriteLine(i);
    }
}

1 answer

5


You have to remove the semicolon after the for

for(int i = a; i <= b; i++); // <<-- Isso tá errado

It must be so:

for(int i = a; i <= b; i++)
{
    if(i % N == 0)
    {
        Console.WriteLine(i);
    }
}
  • Perfect, thanks LINQ for!

  • 2

    @Adrianosanches I don’t know if you already know how the site works, but whenever you ask a question you can mark an answer as correct using the V on the left side of the response

Browser other questions tagged

You are not signed in. Login or sign up in order to post.