Difference between revisions of "SHIP:Sail:Flow Control:switch"

From Serious Documentation
Jump to: navigation, search
(Created page with "== See Also == *Sail Home *Flow_Control *if *break *SHIP:Sail:Flow_Co...")
(No difference)

Revision as of 14:31, 3 October 2016

See Also

Template:SHIP:Sail:Flow Control

Branch control to follow one of multiple possible parallel branches.

Statement Description
Template:Flow Control:switch Takes an integer value. Code execution branches according to the case that matches the integer value.

Example

switch(a) {

  case 1:
     printf("1\n");
     break;
  case 2:
     printf("2\n");
     break;
  case 3:
     printf("3\n");
     break;
  case 4:
     printf("4\n");
     break;
  default;
     printf("default\n);
     break;

} Prints: a = 1 ->1 a = 2 ->2 a = 3 ->3 a = 4 ->4 a = 20 ->default