Switch Statement - StarShipTutor/StarshipTutorAPCS GitHub Wiki

The execution jumps to the case labeled with the matching integer n. The switch parameter can be byte, char, int, enum or String.

int caseIndex;
...
switch( caseIndex )
{
   case 1:                         // Start here if n == 1
     // Execute code block #1
     break;                        // Exit Switch

   case 2:                         // Start here if n == 2
     // Execute code block #2
                                  // No Break fall through to next case

   case 3:                         // Start here if n == 3
     // Execute code block #3
     break;                        // Stop here

   default:                        // If all else fails...
     // Execute code block #4
     break;

}; // On break execution continue after this line

In addition the 'break' statement can jump forward or back to a labeled location.

labelOne: // Code location labeled by labelOne:
...

If ( jumpTolabelOne == true )
{
   break labelOne;
} else {
   break labelTwo;
}

...

labelTwo: // Code location labeled by labelTwo: