Reputation: 11
This is my first loop assignment, so I am struggling to find the error, but the code looks like this:
//Loop
for (yearDisp == startYr; yearDisp <= endYr; yearDisp++); <-EMPTY STATEMENT ERROR
{
listBoxDisp.Items.Add("Year:" + yearDisp.ToString());
yearDisp = yearDisp + 1;
I might be putting the whole thing together wrong.. I need to create something like this: User enters two years (ex: 1988 and 2022) and when I hit the "GO" button, the loop needs to display each year in the listbox starting with 1988, and 1999, 2000, etc all the way to 2022. Then it needs to stop.
Where am I going wrong, and why it that semicolon creating a "possible empty statement error?
Thanks in advance.
Upvotes: 0
Views: 49
Reputation: 10162
yearDisp == startYr
should be yearDisp = startYr
. It's an assignment not an equality check.I am not sure if it's by design, but you're iterating your yearDisp
twice. Once by yearDisp++
and second time by yearDisp = yearDisp + 1
. If you only mean to do it once, get rid of one of them.
for (yearDisp = startYr; yearDisp <= endYr; yearDisp++)
{
listBoxDisp.Items.Add("Year:" + yearDisp.ToString());
//yearDisp = yearDisp + 1; <-- may be a design error, do you need this one?
}
Upvotes: 2