RThomP RThomP - 1 year ago 298
Java Question

Java compilation error - continue cannot be used outside of a loop

Getting an error where the Eclipse Java IDE is giving me trouble with continue statements:

double sum = 0.0;
double avg = 0.0;
for (i=0 ; i<daRun1.length ; i++);
if(daRun1[i] == max || daRun1[i] == min)
continue; //<-- **this is where the error is showing (underlined in red in eclipse)**
sum += daRun1[i];
avg = sum / (daRun1.length-2);

System.out.println("The average score is: " + avg);

What's wrong with my code? This exact if loop was used in a demonstration and there were no problems.

Answer Source

The problem is that continue is not in the for loop.

You end the loop with the semi-colon here:

for (i=0 ; i<daRun1.length ; i++);

Remove the semi-colon, and it shall work fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download