OpenModelica


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;

Administrator has disabled public posting. Please login or register in order to proceed.

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

Administrator has disabled public posting. Please login or register in order to proceed.

Re: loop script error

Thank you,

Administrator has disabled public posting. Please login or register in order to proceed.
There are 0 guests and 0 other users also viewing this topic