0
Developing some scripts in Ruby I come across the following situation:
There are indeed several Repetition Structures, but 2 in particular caught my attention. while true
and loop do
. Both generate what everyone knows as "infinite looping". But there is something that makes one more performative than the other!?
In the case of loop do
it will perform the action infinitely or until I establish (establish) a stopping condition. Ex:
count = 1
loop do
puts count
count += 1
end
But taking this logic to the while true
we have implicitly the explanatory "he will perform as long as the condition is true", but what condition!? Ex:
count = 1
while true
puts count
count += 1
end
In addition to the syntax issue, there is something that differentiates them in the sense of performance or there may be something in my code that could cause problems in one of the 2 loops (maybe this 'true' no while)?
When should I use each of them?