img

Return Statement

The return statement terminates the current function and returns the control into the calling function to the point immediately following the function call.

The expression value, if specified, is returned to the calling function. If there is no return statement in a function, the execution finishes after the last operator of the function and the control transfers into the calling function.

If the function does not return any value, the return type void should be used.

Example. Using return statement.

 int Run() { System.Print("Max = "+findmax(55, 52)); return 0; } int findmax(int a, int b) { if(a>b)return a; else return b; } 

Example. Using return to exit the function.

 void DealInfo(int i) { if(i<0) { System.Print("i<0, exit"); return; } // processing the value i; }