LearnFrenzy
Sign in Take a free test

Control Flow Statements · Find the Error · Question 9

Error: continue outside a loop Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
public class Main {
    public static void main(String[] args) {
        int stock = 0;
        if (stock == 0) {
            System.out.println("out of stock");
            continue;
        }
        System.out.println("in stock");
    }
}
  • A if needs else
  • B continue is only allowed inside a loop; to leave main early use return Correct
  • C stock must be boolean
  • D println cannot be in if
Correct Answer: Option B

break is also only allowed in loops, switches or labelled statements.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links