Home > DeveloperSection > Forums > for loop dead code in java
Takeshi Okada
Takeshi Okada

Total Post:89

Posted on    December-21-2015 10:24 PM

 Java Java 

 1 Reply(s)
 850  View(s)
Rate this:
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;    

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    December-21-2015 11:50 PM

Problem is in this line:

if(p % i == 0); 
Remove semicolon and try again

Don't want to miss updates? Please click the below button!

Follow MindStick