views:

48

answers:

3

it says not all code paths return a value

private string Fisrt(string nonTerminal)
    {
        for (int j = 0; j < 6; j++)
        {
            if (Tokens[j, 0] == nonTerminal)
            {
                if (char.IsLower((char)Tokens[j, 3][0]))
                    return (Tokens[j, 3]);
                else
                    Fisrt(Tokens[j, 3]);
            }
        }
    }
+1  A: 

For example, what if none of the Tokens[j, 0], with j values 0 to 5, is nonTerminal?

Or, if Tokens[j, 3][0] is never lowercase?

Lauri Lehtinen
+1  A: 
private string Fisrt(string nonTerminal)
    {
        for (int j = 0; j < 6; j++)
        {
            if (Tokens[j, 0] == nonTerminal)
            {
                if (char.IsLower((char)Tokens[j, 3][0]))
                    return (Tokens[j, 3]);
                else
                    return Fisrt(Tokens[j, 3]);
                 /* ^ add a return here */
            }
        }

        return SOMETHING;
     /* ^ You also need to add some return value here */
    }

You also need to decide what string value (or null) to return in the event your for loop exits normally.

Dolph
What if `Tokens[j,0]==nonTerminal` is never true?
Ken
@Ken, thanks - revised.
Dolph
+1  A: 

You should return the recursive step

`return First(Tokens[j, 3])`

and handle the cases outside the outer for and if.

Chubas