Java's standard unreachable statement

Asked 2 years ago, Updated 2 years ago, 59 views

I wrote the code that came out of the standard Java code and tried it.

public class SampleNameFor {
    public static void main(String[] args) {
        Loop1:for (int i = 2; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (j == 5)
                    break Loop1;
                    break; 여기서 from here
                    Continue Loop1; 여기서 Unreachable statements. Please tell me the solution.
                    continue;
                System.out.println(i + "*" + j + "=" + i * j);
            }
            System.out.println();
        }
    }
}

java code error

2022-09-22 18:28

2 Answers

Wouldn't it be an example of choosing one out of four conditions?

public classSampleNameFor {
    public static void main(String[] args) {
        Loop1:for (int i = 2; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (j == 5)
                    Break Loop1; // Select one of the four conditions if(j==5)

                System.out.println(i + "*" + j + "=" + i * j);
            }
            System.out.println();
        }
    }
}


2022-09-22 18:28

break Loop1; Determine if there is a condition that can be executed below the line.

It's a simple logic problem.

Loop1 ends when variable j becomes 5.

The arrow line in the question is "Unreachable Sentence" as the error message states.


2022-09-22 18:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.