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

Using for loop to assign variable

Using for loop to assign variable

Hallo everyone,

Code:


Model Foo
  MyModel. M1,M2,M3,...,Mn;
  Real y1,y2,y3,...,yn;

algortihm
  for i in 1:n loop
    yi := Mi.output;
  end for;

end Foo;

So i want to assign each model output from M[i] to its respective y[i] like the model above and got a translation Error.

is it possible to use for loop to assign variable as i intended above? or it only works for array index?

Cheers

Re: Using for loop to assign variable

You must use arrays in that case, you can't construct variable names dynamically like that.

Re: Using for loop to assign variable

perost wrote:


You must use arrays in that case, you can't construct variable names dynamically like that.

Okay, thank you very much.

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