Why is this code giving an “Unreachable Statement” error?

前端 未结 4 478
梦毁少年i
梦毁少年i 2020-12-07 06:23

This is my code and im getting an unreachable statement error on it but i do not know why.

public boolean Boardload(String[] args) throws Exception
{
    Rob         


        
相关标签:
4条回答
  • 2020-12-07 06:37

    The statement while(false) will never execute anything within that loop, thus it's all un-reachable.

    0 讨论(0)
  • 2020-12-07 06:40

    Sorry, but that is some smelly code. I'm not sure what the braces/blocks are doing after declaring your Color local vars, and after declaring your Rectangle var. The main problem for unreachability is while(false), which means it will never execute the associated block.

    0 讨论(0)
  • 2020-12-07 06:51

    while(false) is always false and the loop body is never executed: unreachable. Change to while (true).

    0 讨论(0)
  • 2020-12-07 06:52

    I think the problem is that your loop is

    while(false) {
    

    This loop never executes, because false != true. Consequently, the Java compiler is telling you that nothing in the body of the loop will ever execute, and hence it's unreachable.

    Try changing your loop to

    while (true) {
    

    (the idiomatic "loop forever") and see if that fixes things.

    Hope this helps!

    0 讨论(0)
提交回复
热议问题