Difference between revisions of "Return"

From Scriptwiki
Jump to: navigation, search
 
m (removing test)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== The Return command ==
+
Halts a currently executing script and allows the calling routine to continue processing.
 
 
 
  /return [value]
 
  /return [value]
 +
You can also optionally specify a return value which will be stored in the [[$result]] [[Identifiers|identifier]]. The $result identifier can then be used in the calling routine.
  
The /return command halts a currently executing script and allows the calling routine to continue processing.
+
Value is optional. If value isn't specified, $return and the (possible) [[Custom Identifiers|custom identifier]] give you ''[[$null]]''.
 
 
You can also optionally specify a return value which will be stored in the $result [[Identifiers|identifier]]. The $result can then be used in the calling routine.
 
  
Value is optional. If identifiers doesn't return any existing value, by default is't returned [[$null]].
+
== Example ==
  
 
  [[var]] %c = 1
 
  [[var]] %c = 1
Line 15: Line 13:
 
   [[inc]] %c
 
   [[inc]] %c
 
  }
 
  }
 
+
[[Echo|Echos]] values from 1 to 5.
Returns values from 1 to 5.
+
alias foo { return Today, it's the [[$asctime]](dd.mm.yyyy) }
 
+
//echo -a $foo
 +
This will echo 'Today, it's the <current date>', as $foo returns it.
 +
alias bar { return My name is $1- }
 +
//echo -a $bar(Dana)
 +
This would echo 'My name is Dana', as $1- refers to Dana.
 
== See Also ==
 
== See Also ==
  
 
* [[:Category:Identifiers|Identifiers]]
 
* [[:Category:Identifiers|Identifiers]]
* [[:Category:Custom Identifiers|Custom Identifiers]]
+
* [[Custom Identifiers]]
  
[[Category:Aliases]]
+
[[Category:Aliases]] [[Category:Commands]]

Latest revision as of 09:22, 3 July 2007

Halts a currently executing script and allows the calling routine to continue processing.

/return [value]

You can also optionally specify a return value which will be stored in the $result identifier. The $result identifier can then be used in the calling routine.

Value is optional. If value isn't specified, $return and the (possible) custom identifier give you $null.

Example

var %c = 1
while (%c <= 10) {
  echo -a %c
  if (%c == 5) { return }
  inc %c
}

Echos values from 1 to 5.

alias foo { return Today, it's the $asctime(dd.mm.yyyy) }
//echo -a $foo

This will echo 'Today, it's the <current date>', as $foo returns it.

alias bar { return My name is $1- }
//echo -a $bar(Dana)

This would echo 'My name is Dana', as $1- refers to Dana.

See Also