-2

Here is my code, Eclipse is saying i++ is dead code... why??

for(int i=0;i<packages.size();i++)
        {
            PInfo pinfo = new PInfo();
            pinfo = packages.get(i);
            if(pinfo.pname.contains("com.imdb.mobile"));
            {
            packagesModified.add(pinfo);
            break;
            }
        }

1 Answers1

11

Because of the ; here:

if(pinfo.pname.contains("com.imdb.mobile"));
// ----------------------------------------^

The ; gives the if an empty body, and so the block following it isn't connected to the if, and so your break; always happens and the i++ in the for is never reached.

You don't normally put ; after control statements like for, while, if and such (there are some edge cases where all the logic is in the structure, but usually you need a body block or statement attached to them).


Unrelated, but there's no reason for the new PInfo() here:

PInfo pinfo = new PInfo();
//         ^^^^^^^^^^^^^^-- Unnecessary, since you're about to assign
pinfo = packages.get(i);
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875