Question Unexpected symbol `}' ?

Henry

New member
Joined
Nov 16, 2020
Messages
1
Programming Experience
Beginner
I am getting the error
C#:
 mcs -out:main.exe main.cs
main.cs(30,32): error CS1525: Unexpected symbol `}'
main.cs(30,35): warning CS0642: Possible mistaken empty statement
main.cs(33,32): error CS1525: Unexpected symbol `}'
Compilation failed: 2 error(s), 1 warnings
compiler exit status 1


this is the code

C#:
  public Grid(int Length, int Width)
  {
    length = Length;
    width = Width;
    int Xcount = 0;
    for(length != 0, length -= 1;){
      
      Ycount = 0;
      for(width != 0, width -= 1;){
        coordinatesList.Add(new Coordinates(Xcount, Ycount));
        Console.WriteLine(Xcount, Ycount);
        Ycount --;
      }
      Xcount ++;
    }
  }

please help!
 
The error above is complaining about line 30. You are only showing us 16 lines of code. Either tell us where line 30 aligns with that posted code, or show us a more complete version of your code so that we can get more context about the error.
 
As a quick aside regarding for loops: the syntax is

C#:
for( initialization; condition; postaction )
    action;

Where
initiatilization is where you prepare variables for your loop.
condition is a boolean expression which when true will let the loop action run
postaction is executed after the action and usually where loop variables are updated
action is the instructions to be executed in a loop

Your code above seems to have the condition and post actions in the wrong place.
 
Back
Top Bottom