Java - dead code in for loop

for-loop, java, loops

Solution

Problem is in this line:

if(p % i == 0); 

Remove semicolon and try again

Problem

I'm getting a dead code warning in a for loop at `i++`. Why do I get that, and how do I solve this problem? ``` public static boolean Method(int p) { for(int i = 2; i < p; i++) { // here is the problem, at i++ if(p % i == 0); return false; } return true; } ```

Original source