Ruby does not have a built-in "do...while
" loop. However, you can use the loop
and break
syntax to emulate the behavior of a "do...while
" loop:
i = 0 loop do i += 1 if i == 4 break end end print i #=> 4
Similar to a "do...while
" loop, this loop would execute at least one time, until a break
is encountered.
Hope you found this post useful. It was published . Please show your love and support by sharing this post.