- Index
- » Developer
- » OpenModelica development
- » While loop bug
Page Start Prev 1 Next End
While loop bug
While loop bug
Mar-14-15 01:35:20
WhileLoopBug.mo
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
Mar-14-15 01:45:12
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;
- adrpo
- 885 Posts
Re: While loop bug
Mar-14-15 02:32:14
Depends who. From my side I'm watching some tennis
- adrpo
- 885 Posts
Page Start Prev 1 Next End
- Index
- » Developer
- » OpenModelica development
- » While loop bug
There are 0 guests and 0 other users also viewing this topic