Paul
Paul

Reputation: 26650

Ruby - negative condition in while statement

RubyMine warns me about negative condition here:

while !open_socket do
    sleep 1
end

I know that unless is an opposite to if, but what is the opposite to while ?

Upvotes: 3

Views: 844

Answers (1)

xdazz
xdazz

Reputation: 160843

There is until:

until open_socket do
    sleep 1
end

If there is only one line in it, you could also write as:

sleep 1 until open_socket

Upvotes: 9

Related Questions