Wojciech Brożonowicz
Wojciech Brożonowicz
~1 min read

Categories

Tags

Intro

“Switch” (“Select Case” equivalent in VBA) statement is used to do some action when condition is true. It is similar to if statement but it is better for cases, when You have to check many conditions (many “ifs” are required).

Example

Below simple and easy example for Switch in Java:

int day = 4;
switch (day) {
  case 1:
    System.out.println("Monday");
    break;
  case 2:
    System.out.println("Tuesday");
    break;
  case 3:
    System.out.println("Wednesday");
    break;
  case 4:
    System.out.println("Thursday");
    break;
  case 5:
    System.out.println("Friday");
    break;
  case 6:
    System.out.println("Saturday");
    break;
  case 7:
    System.out.println("Sunday");
    break;
}