Variable in condition of 'for' loop producing compile error in Java


Starting today it seems like whenever I put a variable in the condition part of a for loop in Java the compiler goes nuts and I get an error. Even a very simple example, like this:

public static void main(String args[]) {
    for(int i = 0; i < args.length(); i++){

Produces the following error:

Console output
error: cannot find symbol

    for(int i = 0; i &lt; args.length(); i++){

I didn’t had any problems like these previously, anyone else experiencing the same?



In Java, length() is not a function that can be used on a table. What you may want to do is:
for(int i = 0; i < args.length; i++){}

1 Like