https://github.com/ianbutterworth/simplelooper.jl
A simple looper
https://github.com/ianbutterworth/simplelooper.jl
Last synced: 3 months ago
JSON representation
A simple looper
- Host: GitHub
- URL: https://github.com/ianbutterworth/simplelooper.jl
- Owner: IanButterworth
- License: mit
- Created: 2024-07-26T12:36:04.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-10-18T14:54:42.000Z (8 months ago)
- Last Synced: 2025-02-14T09:15:02.872Z (4 months ago)
- Language: Julia
- Size: 14.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleLooper.jl
[](https://github.com/IanButterworth/SimpleLooper.jl/actions/workflows/CI.yml?query=branch%3Amain)
A simple looper.
```julia
@loop call
@loop n call
@loop bool_expr call
@loop 1.0 call
```Repeat `call` indefinitely until interrupt or `n` times and discard the output.
If an expression is given as a first argument it must return a `Bool` and
repeats will occur until `false`. If a float is given the loop will run for that
many seconds.```julia-repl
julia> @loop println("Hello, World!")
Hello, World!
Hello, World!^C
ERROR: InterruptException:
...julia> @loop 2 println("Hello, World!")
Hello, World!
Hello, World!julia> @loop rand() > 0.5 println("Hello, World!")
Hello, World!julia> @elapsed @loop 1.0 1 * 1
1.000003416
```Useful in the repl for things like:
```julia-repl
julia> @time @loop 100000000 rand()
0.095913 secondsjulia> @profile @loop 2.0 foo()
julia> @profile @loop 10000 foo()
```