0

I was wondering if any of you know how to leave a loop using a command such as "break" in other languages.

Hao
  • 43
  • 1
  • 5

1 Answers1

0

Actually, you can just use "break;" in GAMS as well. Break and continue were introduced with version 24.8.1 (http://www.gams.com/latest/docs/releasenotes/24.8.html#g2481_GAMS). So this works:

set i /i1*i3/;
scalar cnt /0/;

loop(i,
  cnt = cnt+1;
  display cnt;
  break;
);

ps: As an alternative (which also worked with older version of GAMS), you can use a $-condition like this, to get the same behavior as above:

set i /i1*i3/;
scalar cnt /0/, run /1/;

loop(i$run,
  cnt = cnt+1;
  display cnt;
  run = 0;
);
Lutz
  • 2,197
  • 1
  • 10
  • 12