Unreachable code in Java

前端 未结 2 360
粉色の甜心
粉色の甜心 2020-12-12 07:00

I don\'t get what does \"unreachable code\" means ?

Here in the last line of my code double probabilityOfWin = wins / (wins + loses); it says unreachabl

相关标签:
2条回答
  • 2020-12-12 07:45

    This loop here:

    while(GAMES <= 9999)
    {
        ...
    }
    

    resolves to while (true) because the value of GAMES is never modified. So any code that comes after (in your case, double probabilityOfWin = wins / (wins + loses);) is deemed unreachable.

    0 讨论(0)
  • 2020-12-12 07:50

    You did not make any change to the constant GAME. So while loop will never terminate. Last line of code is unreachable. Unreachable means the code never gets executed. For example,

    return 15;
    int a = 12;
    

    Then the last line of code will not get executed because the function has already returned.

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