Opened 10 years ago

Last modified 4 years ago

#2897 reopened enhancement

continue statement for for- and while-statements

Reported by: Per Östlund Owned by: Martin Sjölund
Priority: high Milestone: Future
Component: MetaModelica Version: trunk
Keywords: Cc: Adrian Pop, Peter Fritzson

Description

Modelica/MetaModelica is currently lacking a continue statement for breaking out of the current iteration of a for- or while-loop, which can be somewhat annoying. Considering that C (and pretty much any language with for-loops) already has this builtin it should be fairly trivial to implement. I suggested adding it to Modelica here, but we could implement it in MetaModelica without waiting for that.

Change History (14)

comment:1 by Martin Sjölund, 10 years ago

How would you like it added initially? It requires a lexer change and the keyword continue is used as a variable name in omc. The grammar conflicts such that you cannot have variables named continue.
Change all current uses of continue to cont?

in reply to:  1 comment:2 by Per Östlund, 10 years ago

Replying to sjoelund.se:

How would you like it added initially? It requires a lexer change and the keyword continue is used as a variable name in omc. The grammar conflicts such that you cannot have variables named continue.
Change all current uses of continue to cont?

Sure, it doesn't seem to be used that much currently. continue is pretty universally used for this purpose, so I think it would be confusing to call it something else.

comment:3 by Martin Sjölund, 10 years ago

Milestone: Bootstrapping1.9.1
Resolution: fixed
Status: newclosed

Fixed in r22782.

comment:4 by Martin Sjölund, 10 years ago

Cc: Adrian Pop Peter Fritzson added
Resolution: fixed
Status: closedreopened

We need to decide what continue should do in a match/matchcontinue block. The current implementation is that:

x := match exp
  case _
    equation
      continue; // Continues with the next case
    then fail();
  case _
    equation
      break; // Returns undefined values from the match-expression
    then fail();

comment:5 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:6 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:7 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:9 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:10 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:11 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:12 by Francesco Casella, 7 years ago

Milestone: 1.12.0Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

comment:13 by Per Östlund, 4 years ago

continue is currently used in the following pattern in a few places (Inline.getExpFromArgMap and BackendDAEOptimize.simplifyComplexFunction1):

for ... loop
  try
    ...
  else
    continue;
  end try;
end for;

This is wrong since try-else is just syntactic sugar for a matchcontinue, so this will currently not do what the author intended.

There are however no uses of continue that assume that it continues with the next case, so the logical thing to do would be to change continue and break to only affects loops. That might be easier said than done though...

comment:14 by Martin Sjölund, 4 years ago

Ideally the DAE would contain labels that you would jump to :)

Note: See TracTickets for help on using tickets.