Operators |
Category or name |
x = y , x = {...} |
Assignment |
x || y |
Conditional OR |
x && y |
Conditional AND |
x == y , x != y |
Equality |
x < y , x > y , x <= y , x >= y |
Comparison |
x + y , x - y |
Additive |
x * y , x / y , x % y |
Multiplicative |
x.y , f(x) , a[i] , x++ , x-- |
Primary |
let x: Int = 1;
// const x: Int = 1;
let y: String = "Hello World";
let z: Bool = true;
let a: Array = [1, 2, 3];
let b: Object = { x: 1, y: 1 };
let c: Float = 1.0;
// let d: Enum = Squash;
let e: Any = null;
class IceCream
{
IceCream(flavor)
{
this.flavor = flavor;
}
getFlavor()
{
return this.flavor;
}
serveOn()
{
return "Cones";
}
};
let food: IceCream = IceCream("badFlavor");
food = IceCream("coffee");
print(food.getFlavor());
let servedOn: String = food.serveOn();
print(servedOn);
enum Veggie
{
Squash,
Cabbage,
Broccoli,
}
let cart: Array = [Cabbage, Cabbage, Broccoli];
let veggie: Enum = Broccoli;
print(veggie);
if (veggie == Broccoli)
{
print("We've got the best vegetable!");
}
print("Hello {}", "World");
format("Hello {}", "World");
sleep(1000);
// loops 3 times
loop(3) {
print("ok");
}
// loops infinitely
let i: Int = 0;
loop {
if (i == 2)
{
i = i + 1;
continue;
}
print(i);
if (i == 5)
{
break;
}
i = i + 1;
}
sync
{
loop (50)
{
print("ok");
}
}
sync
{
loop (50)
{
print("ok");
}
}
1;
("Hello World");
true;
false;
null;
let x: Array = [1, 2, 3];
let bar: Object = { x: 1, y: 1 };
print(bar["x"] == bar.y);
1 + 2;
1 - 2;
1 * 2;
1 / 2;
1 % 2;
{
let x: Int = 1;
print(x);
}
print(x); // Error: x is not defined
// Conditional AND (&& or "and")
"ok" and "ko" // "false"
"ok" and "ok" // "true"
// Conditional OR (|| or "or")
"ok" or "ko" // "ok"
false or "ko" // "ko"
// Equality
"ok" == "ok" // "true"
"ok" == "ko" // "false"
// Inequality
"ok" != "ok" // "false"
"ok" != "ko" // "true"
let x: Int = if (true) { 1 } else { 2 };
if (x == 1) {
print("Hello World");
print(if (x != 1) { "hi" } else { "bye" });
}
function foo(): Int
{
return 100;
}
let fmt: String = format("{}: {}", foo(), 300);
print(fmt)
print("{}", 100)
print(foo(), 300)