Java Reference
In-Depth Information
However, if you assign outside of the current bounds of the array, you will get an
ArrayIndexOutOfBounds Exception.
You can also use the for operator to iterate over the elements in the native array.
The following code shows an example of this.
for(i in ints) {
println(i);
}
for(i in ints where i mod 2 == 0) {
println(i);
}
Functions
Functions define behavior. They encapsulate statements that operate on inputs,
function arguments, and may produce a result, a returned expression. Like vari-
ables, functions are either script functions or instance functions. Script functions
operate at the script level and have access to variables and other functions
defined at the script level. Instance functions define the behavior of an object and
have access to the other instance variables and functions contained within the
function's declaring class. Furthermore, an instance function may access any
script-level variables and functions contained within its own script file.
To declare a function, use an optional access modifier, public , protected , or
package , followed by the keyword function and the function name. If no
access modifier is provided, the function is private to the script file. Any function
arguments are contained within parentheses. You may then specify a function
return type. If the return type is omitted, the function return type is inferred from
the last expression in the function expression block. The special return type of
Void may be used to indicate that the function returns nothing.
In the following example, both function declarations are equal. The first function
infers a return type of Glow , because the last expression in the function block is
an object literal for a Glow object. The second function explicitly declares a
return type of Glow , and uses the return keyword.
public function glow(level: Number) {
// return type Glow inferred
Glow { level: level };
}
public function glow(): Glow { // explicit return type
return glow(3.0); // explicit return keyword
}
 
Search WWH ::




Custom Search