Search code examples
rubyequivalentmruby

mruby equivalent of begin ... end until


I'm trying to port a ruby code base to mruby. In ruby (MRI), I can do (and unfortunately, the person who wrote it did)

begin
  statement
end until condition

which executes statement once until and then until condition becomes positive. In mruby, however, the behavior is different, and the condition is evaluated before the first run, so this is equivalent to a while statement. What is the least intrusive alternative to this construct in mruby?

On a side note, is it possible to patch mruby so that this (and other) behavior becomes similar? I mean is there an existing set of patches that do this?


Solution

  • loop with break would probably work:

    loop do
      statement
      break if condition
    end