I have two succeeding function with the same condition and I wonder what is the best way to write this? I know the one way to do this is using if (condition) … end, but I’m wondering if I can do it in one-line similar to bash, ‘[$n == $value] echo “$n” && break’.
n = 0
loop do
puts n if n == value # puts and break is having the same condition, but
break if n == value # can we do it in one line?
n += 1
end
One easy way is to just parenthesize the statements:
If it’s a bit much to put in parentheses, a begin-end will do the trick:
Output: