The Kernel.loop method requires a "do". A semicolon is not allowed?

In some constructions, I have the choice of using the keyword with a comma or doto delimit the end of the statement, as in the example untilbelow.

until x == 100 do puts x; x+=1 end 

until x == 100; puts x; x+=1 end 

But this is not possible with Kernel.loop.

x=0    
loop do puts x; x+=1; break if x == 100 end

x=0    
loop; puts x; x+=1; break if x == 100 end # => error

Is there a reason why this is so?

+3
source share
1 answer
  • loopis a method (c Kernel) that really requires a block with do...endor { }.
  • while until (, if) . do , (, while x == 100 { puts x; x+=1; } , loop { puts x; x+=1; break if x == 100 } .)

, do . loop ( ) ; while, until .. ( , then if.) .

+6

Source: https://habr.com/ru/post/1704703/


All Articles