Prev | Current Page 79 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Also, you
must note that although a variable name may contain numbers, it cannot start with a number.
The final part of the variable declaration is the type. The type name must begin with an uppercase letter.
Assigning a type alerts the compiler to the type of data you wish to store in the variable, so that checks
can be made throughout the rest of your code, thus reducing possible errors at run time.
You can initialize a variable with data when declaring it, though it is not mandatory to do so. To initialize
a variable, simply follow the declaration with an assignment operator ( = ) followed by the value to
initialize your variable, like this:
var varName : Type = ???dataToAssign???;
The data you supply to the variable declaration can be either literal data, as in the preceding example, or
data contained within an existing variable.
To declare a variable, enter the following code into a new file and save it as VariableAssignment.hx :
class VariableAssignment
{
public static function main()
{
(continued)
Part I: The Core Language
30
var flt:Float = 10.


Pages:
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91