-
-
Notifications
You must be signed in to change notification settings - Fork 3
Features Handbook
Standard Calculations
10 + 10 // plus
10 – 10 // minus
10 * 10 // multiply
10 / 10 // divide
10 ** 3 // power (>> 10 * 10 * 10)Priorities (From highest to lowest):
- brackets
- square
- multiply, divide
- plus, minus
Brackets are processed prioritised.
10 – (3 + 10) // >> -3To compare different values we have 5 comparison operators
== // equals
>= // bigger or equal
<= // lower or equal
> // bigger
< // lowerYou can use them like that
10 > 9 // Will return true because 10 is bigger than 9
10 > 10 // Will return false because 10 is not bigger than 10There are 3 boolean operators to concatunate booleans
|| // or operator returns true if at least one of both provided values is true
^ // xor operator returns true if just one, but not two of both provided values, is true
&& // and operator only returns true if both provided values are true There are two ways that are fine and do basically the same
int i;
var i : int;Variable initialization with value assignment
int i = 0
var i : int = 0There are a few basic variable types integrated in the compiler
| Type | Size | Description |
|---|---|---|
| byte | 1 byte | Stores whole numbers from -128 to 127 |
| short | 2 bytes | Stores whole numbers from -32,768 to 32,767 |
| int | 4 bytes | Stores whole numbers from -2,147,483,648 to 2,147,483,647 |
| long | 8 bytes | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
| float | 4 bytes | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits |
| double | 8 bytes | Stores fractional numbers. Sufficient for storing 15 decimal digits |
| boolean | 1 bit | Stores true or false values |
| char | 2 bytes | Stores a single character/letter or ASCII values |
Complex data types can store more than just a number, they can store multiple values. They are base of the object oriented programming
| Type | Description |
|---|---|
| String | Strings store text, text is no simple data, it is stored in a complex data type. |
Standard assignment
i = 0 Calculation assignments Only works for supporting types, e.g. numbers
i += 2 // Add to variable
i -= 2 // Subtract from variable
i *= 2 // Multiplicate variable
i /= 2 // Divide variable
i **= 3 // Power variableBoolean Assignments
bool1 |= bool2 // Saves into bool1 if either bool1 or bool2 is true
bool1 &= bool2 // Saves into bool1 if bool1 and bool2 are both true
bool1 ^= bool2 // Saves into bool1 if either bool1 or bool2, but not both, are trueConstants are basically variables with fixed values You can use a standard variable initialization with the final keyword before. Constants need a value when they are initialized because you can’t assign a value later
final int i = 0DO NOT use this syntax with var, the compiler will process it, but it is bad Syntax, just remove the var keyword int this case
final var i : int = 0 // << Bad Syntax
const i : int = 0 // << Better Syntax3.0 if-else Statement An if-statement needs a boolean input and executes an action if the boolean value is true
if ( condition ) { … }if the statement is false you can also execute an else statement
if ( condition ) { … }
else { … }If the code the if-statement should execute is just one line long, you can also write them inline
if ( condition ) doSomething();
else doSomethingElse();You can also chain if-statements
if ( condition ) { … }
else if ( condition ) { … }
else { … }While loops are the first basic loops. They just get a condition and execute as long as the condition is true
while ( condition ) { … }They can also be written inline
while ( condition ) doSomething();Do-While are much like while loops, but they execute once before the condition is checked
do { ... } while ( condition );They can also be written inline
do doSomething(); while ( condition );For loops are designed to loop with a counter. You can for example count to ten and run a function ten times
for(int i = 0; i < 10; i++>) { ... }They can also be written inline
for(int i = 0; i < 10; i++>) doSomething();Functions can be written in two different styles. You can write them in a JavaScript style:
function doSomething() { ... }The other variant is to code them in a c-style:
void doSomething() { ... }A function can has a declared return type. C-Style always declares a return-type. If your function returns an int for example the function declaration works like that in c-style
int returningFunction() { ... }...and in JavaScript-Style
function returningFunction() : int { ... }If a function returns nothing, it's type is void
C-Style:
void doSomething() { ... }JavaScript-Style:
function doSomething(): void { ... }Function calls always work like that
myFunction();You can also put the parameters inside the function call
println(42);You can declare function parameters in the brackets. There are also two styles, C-Style and JavaScript style.
C-Style parameter declaration:
function f(int i) { ... }JavaScript-Style parameter declaration:
function f(i : int) { ... }