- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Loops in MOS script with...
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?
- DarioMangoni
- 45 Posts
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.
- DarioMangoni
- 45 Posts
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.
- adrpo
- 885 Posts
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.
- adrpo
- 885 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Loops in MOS script with...