Search code examples
rubyblock

Is it necessary to use `do` after condition?


  • This is the official syntax for a while loop:

    while condition [do]
       code
    end
    

    But I saw some examples without the do after the condition. I was wondering if it is necessary.

  • Is there a loop that is equivalent to the Java do...while loop? If so, then let me know please


Solution

  • The 'do' is optional for the while loop.

    You can use:

    begin
      # do something
    end until quit == true
    

    for a 'do...while' loop.