Unreachable code

Unreachable code is a section of code in a program that can never be executed. 

Having unreachable code is bad because it wastes space on the disk, memory, and CPU cache.

Luckily, many modern compilers alert the programmer with a warning or error whenever it detects unreachable code.

 Example 
    void beepForever() {
      while (true) {
          System.out.println("Beep!");
      }
      System.out.println(":'(");
  }


In this example, ":'(" will never be printed because the loop never exits.

 Category:Computer programming


 References