Explanations for While and For in Help File please?

Hi Sam,

I’ve noticed people using while and for in their code recently,
and that there is no F1-help for these commands. In between
everything else, could they be added please?

Also, the auto-indent doesn’t seem to like while… it
glitches with a while in a live_loop? Very confusing…

Ta muchly!


 live_loop :melody_background_beat do
    cue :background_beat
    while (song_ended == 0) do
        sample :drum_heavy_kick,amp:2.5
        sleep 1
        sample :drum_snare_soft,amp:2.5
        sleep 1

Re the docs, I think it was a deliberate decision to leave commands such as while and for out, as they are not part of the official Sonic Pi syntax per se. They are part of the Ruby language.

1 Like

There are many constructs inherited from Ruby which may or may not work, and by all means use them.

However, as @ethancrawford correctly points out, only the code documented in the tutorial and help system is officially supported.