Functions

Parent Previous Next

Functions.

SCRAMBLECODE execution is always done by functions. You can't have code that executes outside of a function.


The most simplistic function has no input parameters and does not return anything:


 Function Foo()

 {

   //The function body with a block of code statements.

   //Sometimes we may refer to this as a code block.

 }


Let's expand this function step-by-step.


Now the function has two input parameters - both are integers - and both are passed by value:


 Function Foo(Integer param1, param2)

 {

 }


Now we add an extra type (separated by a semicolon) and a parameter that is passed by reference (the ampersand):


 Function Foo(Integer param1, param2; String &param3)

 {

 }


Expand the function to return a value of type integer using a colon as separator:


 Function Foo(Integer param1, param2; String &param3) : Integer

 {

 }



Public or Private Access.

Functions can be given an access identifier to indicate whether they are a public or private member of the class. This is described in detail in the Class section.


 Public  Function Foo1(Integer param1, param2; String &param3) : Integer { }


 Private Function Foo2(Integer param1, param2; String &param3) : Integer { }


If no access identifier is specified, the function has private scope.



Overloaded Functions.

Functions within a class can be overloaded and have the same name provided they have the same scope and differ in their argument-signature. They do not need to return the same type.


Example of three overloaded functions:


 Public Function Foo(Integer param1) : Integer

 {

 }


 Public Function Foo(Integer param1, param2) : Integer

 {

 }


 Public Function Foo(String param1) : String

 {

 }