/* switch statement syntax

 switch (expr) {
    case constant1:
       statements;
       break;
    case constant2:
       statements;
       break;
    default:
       statements;
    }
 
 Expression:  must be of type int, short, char, byte, enum
 Constants:   must be compile-time constants.  So, no variables!
 */

enum MyEnum { FOO, BAR }

public class TestSwitch {
   public static void main(String[] args) {
      test1();
      test2();
   }
   
   //illustrating switch statement with integers
   static void test1() { 
      System.out.println("***test1***");
      for (int i = 0; i < 5; i++) {
         switch (i) {
            case 0:
               System.out.println("0!");
               break;
            case 1:
               System.out.println("1!");
               break;
            case 2:
               System.out.println("2 is bad!");
            case 3:
               System.out.println("3! This is what happens with no break!");
               break;
            default:
               System.out.println("int not known!");
         }
      }
   }
   
   //illustrating switch statement with enum
   static void test2() {      
      System.out.println("***test2***");
      for (MyEnum e : MyEnum.values()) {
         switch (e) {
            case FOO:
               System.out.println("foo!");
               break;
            case BAR:
               System.out.println("bar!");
               break;
            default:
               System.out.println("unknown!");
         }
      }
   }
}

/* Output:

***test1***
0!
1!
2 is bad!
3! This is what happens with no break!
3! This is what happens with no break!
int not known!
***test2***
foo!
bar!

 */
