DeveloperSection

Home / DeveloperSection / Forums / Missing return statement in loop

Missing return statement in loop

Elena Glibart 1961 05-Nov-2014

I have a two-dimensional boolean array 'poorSignal' and need to write a method that returns a grid, where if a point on the array is true an X is displayed, if false an O is displayed. Here is my code:

    public String display()
{
    for(int i = 0; i < mapSize; i++)
    {
        for(int j = 0; j < mapSize; j++)
        {
            if(poorSignal[i][j] = true)
            {
                return 'O ';
            }
            else
            {
                return 'X ';
            }
        }
        return '\n';
    }
}

When I compile, it gives me 'missing return statement' on the very last line of the method. I am also unsure if the 'return '\n' will work to add a new line when printing the array.

It's a question for an assignment, so I can't print it directly or just print the boolean values - it must be a method that produces the grid.


Updated on 05-Nov-2014
Elena Glibart

Elena Glibart

Leave Answer


Please enter your answer.


1 Answers

Liked By