Range Over Built in Modelica
Based on the code and the explanation provided, here is the corresponding Modelica code:
Our first program will print the classic “hello world” message. Here’s the full source code.
To run the program, save the code in a .mo
file and use the OpenModelica compiler omc
to execute it:
We have successfully printed the “hello world” message using Modelica. Let’s learn more about the language by exploring more examples.
Here we use a loop to sum the numbers in an array. Arrays work like this too.
The above code sums the array elements using a for
loop and prints the result:
To iterate over arrays and get index and value for each entry, although Modelica does not have a direct way to ignore indices like _
, you can simply access both.
Output:
Modelica also allows iterating over key/value pairs in a dictionary-like way using records, but it’s more common to handle key-value arrays.
Output:
To iterate over just the keys, one can simply access the key field of the record.
Output:
Iterating over strings requires accessing string characters individually.
Output:
Now that we understand how to perform these iterations in Modelica, let’s continue to explore more features of the language.