Core Function Return

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
Line 1: Line 1:
 
<pre>
 
<pre>
 
Return <expressions>
 
Return <expressions>
 +
yield Return <expressions>
 
</pre>
 
</pre>
  
 
=== Description ===
 
=== Description ===
  
Return from a function with a value.
+
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 24:
 
=== Remarks ===
 
=== Remarks ===
  
N/A
+
If you add yield before the Return it will save the current iteration of a loop and start from that point again the next time you use that loop (as long as the arrays internal pointer hasn't changed position).
  
 
=== Example ===
 
=== Example ===
 +
 +
A simple numeric return
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
Line 29: Line 38:
 
{
 
{
 
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]]

Revision as of 03:51, 23 September 2013

Return <expressions>
yield 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

If you add yield before the Return it will save the current iteration of a loop and start from that point again the next time you use that loop (as long as the arrays internal pointer hasn't changed position).

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;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox