GassaFM / interpr

Toy language to learn parallel computing
MIT License
5 stars 4 forks source link

Break statement #8

Open acforvs opened 4 years ago

acforvs commented 4 years ago

It would be nice to have break statement

GassaFM commented 4 years ago

While it would indeed seem nice to have break, language features should generally be worth implementing. Currently, we can use a rewrite. If the program was:

while condition:
    statements1
    if mid1:
        break
    statements2
    if mid2:
        break
    statements3

Then it can be written as such:

ok := 1
while ok & (condition):
    statements1
    if mid1:
        ok := 0
    if ok:
        statements2
    if mid2:
        ok := 0
    if ok:
        statements3

So, while it a bit lengthy, the solutions requiring break are currently doable with such rewrite. Is there a solution which is critically affected by the lack of break, as in, it times out if we use a rewrite but would pass if we had break?

acforvs commented 4 years ago

@GassaFM yeah, we can surely use a rewrite, and unfortunately (or fortunately) I do not know the solution that is critically affected by the lack of break. However, the break looks like a doable feature that can speed some solutions up and provide much more readable code, so I opened this issue.