Getting Started
A script in AddyScript is any sequence of statements. Even an empty file is a valid script. A statement is anything from an
import directive to a
try-catch block. There is no special order in which you should arrange your statements. For example, you can assign a variable, then declare a class and after that call a function. Some statements embed others. However, there is a subset of statements that are not embeddable. These include import directives, class declarations and function declarations. They can only be used at the root level (i.e. out of any block). Below are some examples of scripts:
A simple "Hello World"
println('Hello World!');
The sum and averrage of n numbers
n = (int) readln('How many numbers? ');
sum = 0;
for (i = 0; i < n; ++i)
{
print('Item number {0}: ', i + 1);
sum += (float) readln();
}
println('The sum is {0}', sum);
println('The averrage is {0}', sum / n);
A function to say "Hello"
function hello(name)
{
println('Hello ' + name);
if (name == 'roger')
println('Have you been a football player?');
}
names = ['john', 'mike', 'bill', 'david', 'mark', 'roger'];
// Hello to anyone:
foreach (name in names)
hello(name);
// Another way to do the same stuff:
names.each(hello);
// Or without declaring the 'hello' function at all:
names.each(function (x)
{
println('Hello ' + x);
if (x != 'bill') return;
println('Have you been a CEO somewhere?');
});
Well, now you can try your own.