SHIP:Sail:Flow Control:return

From Serious Documentation
Revision as of 12:22, 4 October 2016 by CarltonHeyer (talk | contribs)
Jump to: navigation, search

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