Random Tip

Show students examples of unreachable code to help them reason about how conditionals are executed.

Share Show students examples of unreachable code to help them reason about how conditionals are executed. with FacebookShare Show students examples of unreachable code to help them reason about how conditionals are executed. with Twitter
  • By setting up examples where a conditional will never execute, you can help students reason about the fact that conditionals only execute under certain conditions.
    • For example, in the following Java code, if x<0, x cannot be >100, so the print statement is unreachable.
      • if (x < 0) {
          if (x > 100) {
            System.out.println("Ooops - we can never get here!");

          }

        }