-
Notifications
You must be signed in to change notification settings - Fork 0
Statements
Kotov edited this page Dec 11, 2023
·
3 revisions
You can use any expression as an statement like in C:
2 + 2 * 2;
if
statement in SLThree like in C:
if (true) { }
if (true) { } else { }
But you can't do that:
if (true) true;
else false;
The following is true for all loops:
-
break;
breaks the loop -
continue;
start new iteration of loop - As with the
if
, the loop body must be between{
}
while
in SLThree like in C:
using console;
a = 0;
while ((a += 1) < 10) { console.println(a); }
foreach
in SLThree almost like in C#:
using linq;
foreach (x in linq.range(1, 10)) { global.println(x); }
This example uses linq
, see more details
switch
statement in SLThree almost like in C#, but:
- You don't need to use
break;
- You can use non-constant expressions in
case
- Not supported yet
default:
using console;
a = conosole.readln() as i64;
switch (a > 0) {
case false: console.writeln("<=0");
case true: console.writeln(">0");
}
Unlike C#, in SLThree using
loads not a namespace, but a type. Loading types is needed to access static members:
using System.Math;
Math.Pow(2.5, 2);
In addition, using
can be used for shortened initialization of objects:
rand = new System.Random();
using System.Random as r;
rand = new r();
r.Next(0i32, 100i32);
return
works exactly like in C#:
func = a => {
return a * 2;
};
func(2);
To find out what a context is, follow here.
Similar to new context expression, but:
- For LANG 0.5.2 cannot be anonymous
- You can set the type cast via
: T
insteadnew context {} as T
context A {
b = 2;
}
context B: SLThree.LongLiteral {
Value = 2;
}
B.GetValue(null);
This article is valid for LANG 0.5