Warning : FOR loop nested statement unnecessary.

  • 25 January 2022
  • 2 replies



I have the following warning : Usage of directly nested for statements is unnecessary and inefficient.

How am I supposed to write this code to avoid the warning ?


for gdm::iNode do

    for (gdm::iTime in gdm::calHorizon) do

        p1(gdm::iNode):=p2(gdm::iNode,gdm::iTime)*p3(gdm::iNode) ; 




Thank you


Best answer by gdiepen 26 January 2022, 13:12

View original

2 replies

Userlevel 5
Badge +7

Often you will not need explicit for-loops in AIMMS. The big advantage of not using them is also speed-up of your code ;)

With regards to the nested for-loop, you could rewrite this to something like:

for (gdm::iNode, gdm::iTime) | gdm::iTime in gdm::calHorizon do
endfor ;

This means, loop over all combinations of iNode and iTime for which holds that iTime is in calHorizon.

However, it is not clear here what you want to do with the value of p1. Right now it would always take the p2 value of the last gdm::iTime and multiple that with the p3 value. So if you have multiple iTimes, it woud always calculate the p1 with the first iTime, then the second element, then the third, etc.

Is this what you want to achieve, or should p2 be the sum?

In both cases, you might be able to write just a single assignment statement that would do this assignment without an explicit for-loop.


Your answer is perfect thank you !


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator