Question on loops


#1

So I've really coded Python for the most part, but I figured I'd give Ruby a shot. Is there any real difference between these two loops? (Other than the fact that one is obviously more text)

i = 1
loop do
    break if i > 30
    
    print "Ruby!"
    i += 1
end

i = 1
while true do
    if i > 30 then
        break
    end
    
    print "Ruby!"
    i += 1
end

#2

In my opinion, the first is just "minified", and open for more continuity; unlike the other which is preconditioned for the loop. i.e, true.

Another thing will be to look at the speed! Lol! :blush:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.