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

From Serious Documentation
Jump to: navigation, search
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:continue|continue]]
 
*[[SHIP:Sail:Flow_Control:continue|continue]]
 
*[[SHIP:Sail:Flow_Control:break|break]]
 
*[[SHIP:Sail:Flow_Control:break|break]]

Revision as of 12:18, 4 October 2016

See Also

return

Causes execution to exit a function or program and go back to caller.

Statement Description
return Causes immediate termination of a function. Can pass a value back to the caller when a value is placed as its argument.

Example

int foo_1()
{
   a = 10;
   while(a)
   {
      if(a == 5)
         return a;
   }
}

or

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

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