Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unreachable code detected in simple method with only one return

I know there’s a bunch of related questions but I only have one line returning from this method and can’t see why the return line would be unreachable:

public List<int> GetMiddleLaneForAI(Room r)
{
    int laneCount = GetLaneCount(true);
    List<int> matches = new List<int>();

    for(int x = 0; 0 < 5; x++)
    {
        if(aiCardFrames[x].deployedCard == null)
        {
            if (laneCount < 3)
            {
                matches.Add(x);
            } else
            {
                if (x > 0 && x < 4)
                {
                    if (aiCardFrames[x - 1] != null && aiCardFrames[x - 1] != null) matches.Add(x);
                }
            }
        }
    }
    return matches.Count > 0 ? matches : null; // unreachable code detected
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Look closely at this line:

for(int x = 0; 0 < 5; x++)

When does this for loop exit? 😉

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading