Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the unreachable code?

int x;
int iHateDataRows = dt.Rows.Count + 2;
System.Data.DataRow[] dra = new System.Data.DataRow[1000];

for(x = 0; x < iHateDataRows; ++x)

So, this is obviously a loop but, my problem is that the ++x tells me that it is unreachable. I don't know if this is just my IDE going crazy or something (I use SharpDevelop, mostly because VS2008 is too clunky and doesn't have neat little features that I like.)

I hope I provided enough info for someone to guess at the problem. I have stared at this thing, changed the variables. Everything, it won't budge.

EDIT:

This is after the for loop:

if(dra[x].ItemArray[2].ToString() == "0")
{
    return x.ToString();
}
else
{
    return "Fail";
}

I sure hope this code is correct as I never got to test it.

like image 974
Mashew Avatar asked Jul 18 '26 00:07

Mashew


2 Answers

You are always returning from the loop before it goes to the next iteration. That is, both halves of the "if" statement return. You never go back to the top of the loop.

like image 81
Talljoe Avatar answered Jul 19 '26 14:07

Talljoe


You probably have a break or return (or, heaven forbid, goto) inside the loop.

like image 32
SLaks Avatar answered Jul 19 '26 12:07

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!