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

From Serious Documentation
Jump to: navigation, search
(Created page with "== See Also == *Sail Home *switch == {{Flow_Control:case|case}} == <onlyinclude>Branch control that works in conjunction with the swi...")
 
Line 1: Line 1:
 
== See Also ==
 
== See Also ==
 
*[[SHIP:Sail|Sail Home]]
 
*[[SHIP:Sail|Sail Home]]
*[[SHIP:Sail:Flow_Control|switch]]
+
*[[SHIP:Sail:Flow_Control:switch|switch]]
  
== {{Flow_Control:case|case}} ==
+
== [[Flow_Control:case|case]] ==
 
<onlyinclude>Branch control that works in conjunction with the switch statement.
 
<onlyinclude>Branch control that works in conjunction with the switch statement.
  
Line 10: Line 10:
 
! scope="col" style="text-align:left" | Description
 
! scope="col" style="text-align:left" | Description
 
|-
 
|-
|{{Flow_Control|case}}||Causes code execution to branch to the matching switch statement expression.
+
|[[Flow_Control:case|case]]||Causes code execution to branch to the matching switch statement expression.
 
|}</onlyinclude>
 
|}</onlyinclude>
 
== Example ==
 
== Example ==
<code>
+
<source lang="c">
 
switch(a)
 
switch(a)
 
{
 
{
Line 30: Line 30:
 
   default;
 
   default;
 
       break;
 
       break;
}</code>
+
}</source>
 
Prints:
 
Prints:
 
a = 1 ->1
 
a = 1 ->1
Line 36: Line 36:
 
a = 3 ->3
 
a = 3 ->3
 
a = 4 ->4
 
a = 4 ->4
 +
 +
[[Category:Flow Control Statements]]

Revision as of 11:17, 4 October 2016

See Also

case

Branch control that works in conjunction with the switch statement.

Statement Description
case Causes code execution to branch to the matching switch statement expression.

Example

switch(a)
{
   case 1:
      printf("1");
      break;
   case 2:
      printf("2");
      break;
   case 3:
      printf("3");
      break;
   case 4:
      printf("4");
      break;
   default;
      break;
}

Prints: a = 1 ->1 a = 2 ->2 a = 3 ->3 a = 4 ->4