Mahdi
Mahdi

Reputation: 175

recursive method - not all code paths return a value!

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]);
            }
        }
    }

Upvotes: 1

Views: 591

Answers (3)

Dolph
Dolph

Reputation: 50650

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.

Upvotes: 1

Chubas
Chubas

Reputation: 18043

You should return the recursive step

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

and handle the cases outside the outer for and if.

Upvotes: 1

Lauri Lehtinen
Lauri Lehtinen

Reputation: 10857

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?

Upvotes: 1

Related Questions