1

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.

3
  • I doubt that the Java Runtime will show a different behaviour. :-) Commented Apr 18, 2016 at 13:09
  • @AndyTurner Not lying, but maybe sometimes not to the point too. (Not related here) Commented Apr 18, 2016 at 13:11
  • 2
    Your brace placement makes this hard to read. If you put opening braces on the same line as for and if you wouldn't make this mistake. Commented Apr 18, 2016 at 13:16

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

Comments

3

Remove the semicolon after the for statement.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.