Core Function Return
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> Return <expressions> </pre> === Description === Return from a function with a value. === expressions === The expressions to return from the function can be a single var...") |
m (1 revision) |
||
(4 intermediate revisions by one user not shown) | |||
Line 5: | Line 5: | ||
=== Description === | === Description === | ||
− | + | Immediately ends execution of the current function, and returns its argument as the value of the function call. return will also end the execution of an Eval() statement or script file | |
=== expressions === | === expressions === | ||
The expressions to return from the function can be a single variable or even arrays. | The expressions to return from the function can be a single variable or even arrays. | ||
+ | |||
+ | This can also just be nothing like | ||
+ | |||
+ | <pre> | ||
+ | return; | ||
+ | </pre> | ||
=== Return Value === | === Return Value === | ||
Line 17: | Line 23: | ||
=== Remarks === | === Remarks === | ||
− | + | None. | |
=== Example === | === Example === | ||
+ | |||
+ | A simple numeric return | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
Line 26: | Line 34: | ||
println("Value is $value"); // Prints 30 | println("Value is $value"); // Prints 30 | ||
− | Function Add ($a, $b) | + | Function Add($a, $b) |
{ | { | ||
return $a + $b; | return $a + $b; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Return an array | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | List( $Name, $ID ) = Test("UberFoX", 777); | ||
+ | |||
+ | println("Name: $Name | ID: $ID"); | ||
+ | // Prints Name: UberFoX | ID: 777 | ||
+ | |||
+ | Function Test( $Name, $ID ) | ||
+ | { | ||
+ | return array($Name, $ID); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | Return nothing | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | $value = Test(); | ||
+ | |||
+ | println("Value is $value"); // Prints 30 | ||
+ | |||
+ | Function Test($a, $b) | ||
+ | { | ||
+ | my $Test = $a; | ||
+ | my $foo = "Bar"; | ||
+ | return; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:38, 14 June 2015
Return <expressions>
Contents |
Description
Immediately ends execution of the current function, and returns its argument as the value of the function call. return will also end the execution of an Eval() statement or script file
expressions
The expressions to return from the function can be a single variable or even arrays.
This can also just be nothing like
return;
Return Value
You decide.
Remarks
None.
Example
A simple numeric return
$value = Add(10, 20); println("Value is $value"); // Prints 30 Function Add($a, $b) { return $a + $b; }
Return an array
List( $Name, $ID ) = Test("UberFoX", 777); println("Name: $Name | ID: $ID"); // Prints Name: UberFoX | ID: 777 Function Test( $Name, $ID ) { return array($Name, $ID); }
Return nothing
$value = Test(); println("Value is $value"); // Prints 30 Function Test($a, $b) { my $Test = $a; my $foo = "Bar"; return; }