switch multiple statements code example

Example 1: multiple case switch javascript

switch (varName)
{
   case "afshin":
   case "saeed":
   case "larry": 
       alert('Hey');
       break;

   default: 
       alert('Default case');
}

Example 2: switch case with multiple conditions

switch (measurement)
{
	case "oz":
		{
          qty = Math.round (qty * 28.3495);
          qty= (int)qty;
          measurement= "g";
          System.out.print(qty);
		}
	break;
	case "fl oz":
        {
          qty = Math.round (qty * 29.5735);
          qty= (int)qty;
          measurement= "ml";
          System.out.print(qty);
      	}
    break;
    default:
        {
          qty =(int)qty;
          System.out.print(qty);
        }
}//end switch case

Tags:

Java Example