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

From Serious Documentation
Jump to: navigation, search
 
Line 34: Line 34:
 
}</source>
 
}</source>
 
Prints:
 
Prints:
a = 1 ->1
+
a = 1 ->1,
a = 2 ->2
+
a = 2 ->2,
a = 10 ->default
+
a = 10 ->default,
 
a = 100 ->default
 
a = 100 ->default
  
 
[[Category:Flow Control]]
 
[[Category:Flow Control]]

Latest revision as of 17:23, 1 November 2016

See Also

default

Branch control that works in conjunction with the switch statement.

Statement Description
default Causes code execution to branch to it if no matching case statement is found.

Example

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

Prints: a = 1 ->1, a = 2 ->2, a = 10 ->default, a = 100 ->default