Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Loops in MOS script with multi-commands body

Loops in MOS script with multi-commands body

Hi,
I see everywhere that OpenModelica MOS scripts use for-loops in this way
e.g.

Code:


s:={j for j in 1:3};

But it seems that a more general notation like this below is not supported

Code:


for j in 1:3 loop
  XXXX
end for:

Now, the problem is: how can I loop over multiple commands in a MOS script?
Is there a way to do it? Am I missing something?



Edited by: DarioMangoni - Dec-05-19 10:28:22

Re: Loops in MOS script with multi-commands body

Ok, I'm really sorry; I was wrestling with this issue since this morning but I realized I incurred in some kind of sub-issue;

Loops do work, but they do not output strings to the command prompt, that it was what I was using to check it.
I'm incurring in some other kind of issue, but it might be that it is again my fault.

Re: Loops in MOS script with multi-commands body

Yes is possible, you would do it as in a Modelica algorithm section.

Code:


for iterator in range loop
  command1;
  command2;
  command3;
end for;

For some examples see:
https://openmodelica.org/forum/default- … r-of-ports
https://openmodelica.org/forum/default- … eter-sweep
For more advanced examples see:
https://github.com/OpenModelica/OpenMod … ateDoc.mos
https://github.com/OpenModelica/OpenMod … ursive.mos
and I guess there are many more examples around.

Re: Loops in MOS script with multi-commands body

Yeah, that's true, the for loop commands do not output as the top level ones. I think this is a bug and we should fix it.

There are 0 guests and 0 other users also viewing this topic
You are here: