Returning a value in Pascal

Clueless picture Clueless · Mar 9, 2012 · Viewed 14.6k times · Source

For a function to return a value in Pascal the assignment FunctionName := SomeVal; is used. I assume it doesn't stop the function execution in that exact place as return in C does. Is there something similar to C return in Pascal? (I'm using FreePascal compiler)

Answer

RRUZ picture RRUZ · Mar 9, 2012

You can use the Exit procedure.

function Foo (Value : integer) : Integer;
begin      
  Exit(Value*2);
  DoSomethingElse();   // This will never execute
end;