mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 07:33:57 +00:00
Update haxe.html.markdown
I think one of Haxes strong point is the fact that control structures are expressions as well. We should point this out.
This commit is contained in:
parent
343c20b4e8
commit
1a9107e43d
@ -284,8 +284,7 @@ class LearnHaxe3{
|
|||||||
trace(modified_n + " is the value for modified_n");
|
trace(modified_n + " is the value for modified_n");
|
||||||
var filtered_and_modified_n [for (val in n) if (n != "foo") n += "!"];
|
var filtered_and_modified_n [for (val in n) if (n != "foo") n += "!"];
|
||||||
trace(filtered_and_modified_n + " is the value for filtered_and_modified_n");
|
trace(filtered_and_modified_n + " is the value for filtered_and_modified_n");
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Switch Statements (Value Type)
|
// Switch Statements (Value Type)
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
@ -311,7 +310,37 @@ class LearnHaxe3{
|
|||||||
trace("My dog's name is" + my_dog_name
|
trace("My dog's name is" + my_dog_name
|
||||||
+ ", and his favorite thing is a: "
|
+ ", and his favorite thing is a: "
|
||||||
+ favorite_thing);
|
+ favorite_thing);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
// Expression Statements
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
trace("***EXPRESSION STATEMENTS***");
|
||||||
|
|
||||||
|
/*
|
||||||
|
Haxe control statements are very powerful because every statement
|
||||||
|
is also an expression, consider:
|
||||||
|
*/
|
||||||
|
|
||||||
|
// if statements
|
||||||
|
var k = if (true){
|
||||||
|
10;
|
||||||
|
} else {
|
||||||
|
20;
|
||||||
|
}
|
||||||
|
|
||||||
|
trace("K equals ", k); // outputs 10
|
||||||
|
|
||||||
|
var other_favorite_thing = switch(my_dog_name) {
|
||||||
|
case "fido" : 'teddy';
|
||||||
|
case "rex" : 'stick';
|
||||||
|
case "spot" : 'football';
|
||||||
|
case _ : 'some unknown treat';
|
||||||
|
}
|
||||||
|
|
||||||
|
trace("My dog's name is" + my_dog_name
|
||||||
|
+ ", and his other favorite thing is a: "
|
||||||
|
+ other_favorite_thing);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Converting Value Types
|
// Converting Value Types
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user