Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A rule for removing (converting) continue statements #202

Closed
sircfenner opened this issue Jun 18, 2024 · 1 comment · Fixed by #227
Closed

A rule for removing (converting) continue statements #202

sircfenner opened this issue Jun 18, 2024 · 1 comment · Fixed by #227
Labels

Comments

@sircfenner
Copy link

As with other rules like remove_interpolated_string and remove_compound_assignment, this would be useful for translating Luau into Lua 5.1 source code.

I implementated this myself a while ago in a different project. It converted the following:

for i = 1, 4 do
    print("start", i)
    if i % 2 == 0 then
        print("two", i)
        continue
    elseif i % 3 == 0 then
        print("three", i)
        break
    end
    print("end", i)
end

into:

for i = 1, 4 do
    local _continue_0 = false
    repeat
        print("start", i)
        if i % 2 == 0 then
            print("two", i)
            _continue_0 = true
            break
        elseif i % 3 == 0 then
            print("three", i)
            break
        end
        print("end", i)
        _continue_0 = true
    until true
    if not _continue_0 then
        break
    end
end

The repeat until true construct is used to execute a block of statements once where it can be broken out of using break.

@ccuser44
Copy link

This would be extremely useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants