Skip to content

Multibreak provides a macro to allow breaking out of several loops at once in Julia code.

License

Notifications You must be signed in to change notification settings

GunnarFarneback/Multibreak.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multibreak.jl

Have you ever wanted a convenient way to break out of multiple nested loops at once in your Julia code?

The Multibreak package provides the @multibreak macro, which allows you to do exactly that. In this contrived but simple example, the break; break line breaks out of both loops:

using Multibreak

@multibreak begin
    for i = 1:5
        if i % 3 > 0
            for j = 1:5
                @show i, j
                if (i + j^2) % 7 == 0
                    break; break
                end
            end
        end
    end
end

More generally the @multibreak macro allows you to break out of any number of nested loops and optionally to continue the next enclosing loop.

Documentation

The tests are the documentation. The tutorial explores the functionality provided by the @multibreak macro.

Background

The @multibreak macro was first implemented as a gist, providing a proof of concept for a proposal in the Julia #5334 issue. The proposed syntax differs by using comma instead of semicolon between break/continue. The former is a syntax error in Julia 1.x, whereas the latter is syntactically valid but semantically useless, making it ideal for a macro implementation.

About

Multibreak provides a macro to allow breaking out of several loops at once in Julia code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages