Return Statement

From NWN Lexicon
Jump to: navigation, search

return Statement

When the return statement is reached within a function it will halt execution and pass the return value to the code block which initially made the function call. If the value being returned does not match the data type of the function, then the compiler will throw a type mismatched error. In the case of void functions, return statements are optional, but can still be used to prematurely halt execution, however if a value is specified after return the compiler will throw a type mismatched error.

// returns a float with the value 0
float someFunction()
{
     return 0.0f;
}

void function return example usage:

// does nothing
void someFunction() 
{
     return;
}




 author: Ryan Hunt, editor: Charles Feduke