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

While loop bug

While loop bug


WhileLoopBug.mo

https://openmodelica.org/images/agorapro/attachments/1539/mini_WhileLooperror.png

Hello,

The following code fragment runs but I do not understand the result. I would expect countks to be constant 10 and count to be constant 0. Instead countks is 11 at the beginning and end and zero everywhere else.

model WhileLoopBug
  Real count;
  Real countks;
algorithm
  count := 0;
  while count < 10 loop
    count := count + 1;
  end while;
  countks := count;
  count := 0;
end WhileLoopBug;

Re: While loop bug

You are missing an noEvent(count < 10)

Code:


model WhileLoopBug
  Real count;
  Real countks;
algorithm
  count := 0;
  while noEvent(count < 10) loop
    count := count + 1;
  end while;
  countks := count;
  count := 0;
end WhileLoopBug;

Re: While loop bug

Aha, okay yes that works. Thanks for the (very) quick reply. Don't you guys sleep in Sweden? ;-)

Re: While loop bug

Depends who. From my side I'm watching some tennis current/smile

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