File: array.ss

package info (click to toggle)
surgescript 0.5.4.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,876 kB
  • sloc: ansic: 13,674; makefile: 16
file content (34 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// array.ss
// Arrays in SurgeScript
// Copyright 2017 Alexandre Martins <alemartf(at)gmail(dot)com>
//

// The following program will print all the elements of the array
// using different pieces of code
object "Application"
{
    array = [1, 2, 3, 4, 5];
    
    state "main"
    {
        Console.print("The array has " + array.length + " elements.");

        // Loop with for
        for(i = 0; i < array.length; i++)
            Console.print(array[i]);

        // Loop with foreach
        foreach(element in array)
            Console.print(element);

        // Loop with iterators
        it = array.iterator();
        while(it.hasNext()) {
            element = it.next();
            Console.print(element);
        }

        Application.exit();
    }
}