for .. if... else

I am trying to iterate over an array, once i have found an index that is still empty i wish to add something to it and then send that index elsewhere (No longer need to iterate over the block). I have the code which doesn't work below and get an error of method not returning a value. Could someone point me in the right direction pls

private int generateMove()

{

for(int i = 0; i<9; i++)

{

if(gameBoard == ' ')

{

gameBoard = 'O';

if(!isWinner('O') && !isFullBoard())

{

toClient.println(i);

}

}

}

}

Thanks

[640 byte] By [ianpwelch85a] at [2007-11-27 4:37:43]
# 1

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

> and get an error of method not returning a value

Well, then return a value. Your method signature says you are going to return and "int" value. Where is your return statement?

camickra at 2007-7-12 9:48:03 > top of Java-index,Java Essentials,Java Programming...
# 2
Obviously putting the int value intotoClient.println(i); doesnt work as was my intention < - - to return the value from there.I am presuming that i will have to get the int to be returned and use another method to send toClient then?.
ianpwelch85a at 2007-7-12 9:48:03 > top of Java-index,Java Essentials,Java Programming...
# 3

Your code does not reflect your intention - and that's the problem.

Invoking toClient.println(i) does not return a value which you expect to happen BUT it passes on the int i to another object as parameter; Your int i variable does not know something about your array BECAUSE it doesn't relate to any of the array object at all. It came from your for-loop variable.

Pass-in the size of the iterator to your generateMove() method before checking against your array - which I suppose is encapsulated in the isWinner() method.

BTW, you will need to provide a more accurate code that you really use in order to get a more accurate help.

eadelarosaa at 2007-7-12 9:48:03 > top of Java-index,Java Essentials,Java Programming...