Reputation: 1180
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.
Upvotes: 1
Views: 4416
Reputation: 5316
See the compilation error shown by Eclipse [ try hover over the red underline]
continue cannot be used outside of a loop
Eclipse is a powerful tool and shows compilation errors while we code.
As mentioned in the error it self : continue
is being used outside the loop, i.e. body of loop has already ended and after that continue is being used. When you see your code you find exact same thing, you can see the semicolons ;
just after the for loop.
Convert
for ( i=0 ; i < daRun1.length ; i ++ );
to
for (i=0 ; i<daRun1.length ; i++)
And continue
will no longer show compilation error.
Upvotes: 1
Reputation: 6077
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.
Upvotes: 8