Fabio Fabio - 7 months ago 8
Java Question

Syntax error on token "<", invalid AssignementOperato

I've search all over google but didn't found any fix... Here's the code:

public Command getCommandbyAlias(String alias)
{
int length;
int i;
for (Iterator localIterator = getCommands().iterator(); localIterator.hasNext(); i < length) //Here, at i < length
{
Command cmd = (Command)localIterator.next();
String[] alias2;
length = (alias2 = cmd.getAlias()).length;
i = 0;
continue;

String aliases = alias2[i];
Utils.addChatMessage(aliases);
if (aliases.equalsIgnoreCase(alias)) {
return cmd;
}
i++;
}
return null;
}

Answer

If you want two conditions in your for statement, you should use the && boolean operator to join them to a single condition:

for (Iterator localIterator = getCommands().iterator(); 
     localIterator.hasNext() && i < length) {

Note, by the way, that you should initialize i and length before you try to use them. You current code does not.

Comments