WMLScript » Statements » return

Syntax:
return

The return statement is used inside a function to set the value of the function. This is the value returned by the call of the function. A function can only return one value. If no value is assigned during the function call, then the function has a default value of an empty string "". Therefore, a called function always returns a value, even if it is just an empty string.

Note that once the return is executed, you immediately leave the function and return to where the function call was made from within the code. The function will now have the value that was returned and you can assign that value to a named variable (use the var statement to initialize the variable).

Examples

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>

<card id="card1">
   <p>
   return example
   </p>
   <do type="accept">
      <go href="ReturnExample.wmls#findreturn()" />
   </do>
</card>

<card id="card2">
<p>
   return = $(rand)
</p>
</card>

</wml>
Explanation:

Code for ReturnExample.wml

Language(s): WML
Code:
extern function findreturn()
{
   var ran = findrandom();
   WMLBrowser.setVar("rand", ran);
   WMLBrowser.go("ReturnExample.wml#card2");
};
 
extern function findrandom()
{
   return Lang.random(1000);
};
Explanation:

Code for ReturnExample.wmls

Language(s): WML

See Also: