O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Blocks

Blocks are important things in haXe, as they can help you write things that might be complicated in some languages in an easy way. Blocks are delimited in the C-style by the { and } characters. What makes them special in haXe is that they have a value and a type. A block's value and type is those of the last expression of this block. Note that empty blocks are of Void type. This type is used to indicate that no value is going to be returned.

Here's an example on how that may ease writing in some cases:

public static function main() : Void
{
var s : String;
s = if(true)
{
"Vrai";
} else
{
"Faux";
}
trace(s);
}

In this example, it will always trace Vrai (which is the French translation of "True"), but I think you get the idea. In most other ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required