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

From Serious Documentation
Jump to: navigation, search
Line 12: Line 12:
 
! scope="col" style="text-align:left" | Description
 
! scope="col" style="text-align:left" | Description
 
|-
 
|-
|{{Flow_Control:return|return}}||Causes immediate termination of a function.  Can pass a value back to the caller when a value is placed as its argument.
+
|[[Flow_Control:return|return]]||Causes immediate termination of a function.  Can pass a value back to the caller when a value is placed as its argument.
 
|}</onlyinclude>
 
|}</onlyinclude>
 
== Example ==
 
== Example ==

Revision as of 11:48, 4 October 2016

See Also

Template:SHIP:Sail:Flow Control: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