Phantom Documentation

[Help Home] [Phantom Home]
return

Syntax:

return variable;
return;


Where,

variable - The variable returned from a function.

Description:
The return keyword is used to exit from a user defined function. The type of the parameter variable must be the same type as the expected return value of the function. If the function returns a void, then a return without a parameter is used.

If return is used in a script, but not inside a function, the return statement exits the script.

Example Code

# Declare some functions
function void f(int i){
  if(i > 5){
    # Return if i > 5
    disp("Returning immediately!");
    return;
  }
  # Wont get here if i > 5
  disp("Did not return.");
}

function int f(int j, int k){
  # Return the sum
  return j + k;
}

function string g(string s){
  if(GetLength(s) <= 0){
    # Return if s is empty
    disp("s is empty... returning");
    return "EMPTY";
  }
  # Wont get here if s is empty
  s = "s is " + s;
  return s;
}

# Call the functions to
# see output
f(10);
f(4);

int i = f(6, 4);
disp(i);

disp(g(""));
disp(g("Phantom"));



See Also: Keywords, User Defined Functions



Copyright 2000-2011 Phantom Automated Solutions