home/ atoms/ sonic-pi-infinite-loop

loop do ... end in Sonic Pi runs forever and prevents any code after it from executing

loop do … end runs the block indefinitely until Stop is pressed. Loops are black holes for program flow: code placed after a loop block is never reached. This means multiple bare loops cannot coexist in one run — threads or live_loops are required for concurrent loops. Sonic Pi raises a safety error if a loop runs without a sleep, preventing CPU lockup.

Examples

loop do play rrand(50, 90) sleep 0.5 end

Code here is unreachable

Assessment

Explain why two consecutive loop blocks in a buffer means only the first is ever heard. Rewrite using in_thread to run both simultaneously.

“loops are like _black hole”
corpus · sonic-pi-built-in-tutorial · chunk 12