Created
September 26, 2015 18:12
-
-
Save ceylonwebide/1a202fe95520b7aaa221 to your computer and use it in GitHub Desktop.
EXAMPLE: Basics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//$webrun_wrapped | |
shared void run() { | |
// Any object can be converted to a string using ".string". | |
// There are no special primitive types, even numbers are objects. | |
Integer i = 3; | |
String s = i.string; | |
"Declarations can be documented using the `doc` annotation. | |
Note that string literals can span several lines." | |
Boolean b = (i == 3); | |
// An attribute annotated "variable" can be re-assigned after it | |
// has been initialized. | |
variable Float f = 0.3; | |
f = 2.0^0.5; // exponentiation | |
// String templates can be used to compose strings. | |
print("The square root of 2 is ``f``"); | |
// With the "value" keyword the type is inferred by the compiler. | |
value t1 = system.milliseconds; | |
print(className(t1)); | |
// some control structures: | |
while (f < 1_000_000.0) { | |
for (j in 1..10) { | |
if (j%3 == 1) { | |
f /= j+1; | |
} | |
else { | |
f *= j+2; | |
} | |
} | |
} | |
print("f=``f`` (``system.milliseconds-t1``ms)"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment