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

loop script error

loop script error

I want to understand for loop. I run this script with  runScript("test.mos")
result of this script
"0

100
"
I am excepting 0- thru 100 count.  Wht only start and stop value print screen?
Oki



test.mos

Code:


j:=0;
for i in 1:100 loop
j:=j+1;
end for;
j;

Re: loop script error

The result of a for-loop is nothing (a void value). If you want to print all values, you can use print(String(j)), writeFile, etc (note that print prints to stdout, not OMShell). Or construct the entire array.

For example using a for-reduction:

Code:

{i for i in 1:100}

Or as such:

Code:

j:=fill(0,100);for i in 1:100 loop j[i]:=i; end for;j

Re: loop script error

Thank you,

There are 0 guests and 0 other users also viewing this topic