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

From Serious Documentation
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== See Also ==
 
== See Also ==
 
*[[SHIP:Sail|Sail Home]]
 
*[[SHIP:Sail|Sail Home]]
*[[SHIP:Sail:Flow_Control|Flow_Control]]
+
*[[SHIP:Sail:Flow_Control|Flow Control]]
 
*[[SHIP:Sail:Flow_Control:if|if]]
 
*[[SHIP:Sail:Flow_Control:if|if]]
 
*[[SHIP:Sail:Flow_Control:break|break]]
 
*[[SHIP:Sail:Flow_Control:break|break]]
 
*[[SHIP:Sail:Flow_Control:case|case]]
 
*[[SHIP:Sail:Flow_Control:case|case]]
  
== [[SHIP:Sail:Flow_Control:switch|switch]] ==
+
== [[SHIP:Sail:Flow_Control|switch]] ==
 
<onlyinclude>Branch control to follow one of multiple possible parallel branches.
 
<onlyinclude>Branch control to follow one of multiple possible parallel branches.
  
Line 13: Line 13:
 
! scope="col" style="text-align:left" | Description
 
! scope="col" style="text-align:left" | Description
 
|-
 
|-
|[[Flow_Control:switch|switch]]||Takes an integer value. Code execution branches according to the case that matches the integer value.
+
|[[SHIP:Sail:Flow_Control|switch]]||Takes an integer value. Code execution branches according to the case that matches the integer value.
 
|}</onlyinclude>
 
|}</onlyinclude>
 
== Example ==
 
== Example ==
Line 36: Line 36:
 
}</source>
 
}</source>
 
Prints:
 
Prints:
a = 1 ->1
+
a = 1 ->1,
a = 2 ->2
+
a = 2 ->2,
a = 3 ->3
+
a = 3 ->3,
a = 4 ->4
+
a = 4 ->4,
 
a = 20 ->default
 
a = 20 ->default
  
[[Category:Flow Control Statements]]
+
[[Category:Flow Control]]

Latest revision as of 17:35, 1 November 2016

See Also

switch

Branch control to follow one of multiple possible parallel branches.

Statement Description
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