mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-05 22:37:42 +02:00
added ternary, some reformatting and fixes
This commit is contained in:
@@ -29,8 +29,8 @@ references.
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
A package declaration isn't necessary, but it's useful if you want to
|
A package declaration isn't necessary, but it's useful if you want to
|
||||||
organize your code into modules later on. Also worth mentioning, all
|
organize your code into modules later on. Also worth mentioning, if you use
|
||||||
expressions in Haxe must end in a semicolon:
|
more than one expression in a code block, it must end in a semicolon:
|
||||||
*/
|
*/
|
||||||
package; // empty package, no namespace.
|
package; // empty package, no namespace.
|
||||||
|
|
||||||
@@ -252,6 +252,9 @@ class LearnHaxe3{
|
|||||||
trace("also not printed.");
|
trace("also not printed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// there is also a "ternary" if:
|
||||||
|
(j == 10) ? trace("equals 10") : trace("not equals 10");
|
||||||
|
|
||||||
trace("Looping and Iteration");
|
trace("Looping and Iteration");
|
||||||
|
|
||||||
// while loop
|
// while loop
|
||||||
@@ -310,13 +313,14 @@ class LearnHaxe3{
|
|||||||
generalized algebraic data types in enums (more on enums later).
|
generalized algebraic data types in enums (more on enums later).
|
||||||
Here's some basic value examples for now:
|
Here's some basic value examples for now:
|
||||||
*/
|
*/
|
||||||
var my_dog_name = 'fido';
|
var my_dog_name = "fido";
|
||||||
var favorite_thing = '';
|
var favorite_thing = "";
|
||||||
switch(my_dog_name){
|
switch(my_dog_name){
|
||||||
case "fido" : favorite_thing = 'bone';
|
case "fido" : favorite_thing = "bone";
|
||||||
case "rex" : favorite_thing = 'shoe';
|
case "rex" : favorite_thing = "shoe";
|
||||||
case "spot" : favorite_thing = 'tennis ball';
|
case "spot" : favorite_thing = "tennis ball";
|
||||||
case _ : favorite_thing = 'some unknown treat';
|
default : favorite_thing = "some unknown treat";
|
||||||
|
// case _ : "some unknown treat"; // same as default
|
||||||
}
|
}
|
||||||
// The "_" case above is a "wildcard" value
|
// The "_" case above is a "wildcard" value
|
||||||
// that will match anything.
|
// that will match anything.
|
||||||
@@ -345,10 +349,10 @@ class LearnHaxe3{
|
|||||||
trace("K equals ", k); // outputs 10
|
trace("K equals ", k); // outputs 10
|
||||||
|
|
||||||
var other_favorite_thing = switch(my_dog_name) {
|
var other_favorite_thing = switch(my_dog_name) {
|
||||||
case "fido" : 'teddy';
|
case "fido" : "teddy";
|
||||||
case "rex" : 'stick';
|
case "rex" : "stick";
|
||||||
case "spot" : 'football';
|
case "spot" : "football";
|
||||||
case _ : 'some unknown treat';
|
default : "some unknown treat";
|
||||||
}
|
}
|
||||||
|
|
||||||
trace("My dog's name is" + my_dog_name
|
trace("My dog's name is" + my_dog_name
|
||||||
|
Reference in New Issue
Block a user