Range Over Built in Scilab

Based on the provided instructions, here is the Scilab translation of the given code example and explanation:

Our first program will showcase how to use for loops to iterate over elements in various data structures. Here’s the full source code.

// Summing numbers in a list
nums = [2, 3, 4];
sum = 0;

for i = 1:length(nums)
    sum = sum + nums(i);
end

disp("sum: " + string(sum));

// Accessing indices and values
for i = 1:length(nums)
    num = nums(i);
    if num == 3 then
        disp("index: " + string(i-1)); // Scilab indexes start at 1
    end
end

// Iterating over a dictionary (map)
kvs = dict("a", "apple", "b", "banana");

for key = kvs.keys()
    value = kvs(key);
    mprintf("%s -> %s\n", key, value);
end

// Iterating over just the keys of a dictionary (map)
for key = kvs.keys()
    disp("key: " + key);
end

// Iterating over a string (over Unicode code points)
str = "go";
for i = 1:length(str)
    char = str(i);
    disp(i-1 + " " + ascii(char));  // Scilab doesn't have 'runes'
end

To run the program, save the code to a .sce file and execute it with Scilab.

$ scilab-cli -f your_file.sce

The output should be:

sum: 9
index: 1
a -> apple
b -> banana
key: a
key: b
0 103
1 111

Now that we can run and build basic Scilab programs, let’s learn more about the language.