Ruby

Ruby

Made by DeepSource

Use while true instead of loop RB-P1002

Performance
Minor

loop can be upto 3x times slower than using while true for unbounded loops.

Bad practice

def slow
  index = 0
  loop do
    break if index > NUMBER
    index += 1
  end
end

Recommended

def fast
  index = 0
  while true
    break if index > NUMBER
    index += 1
  end
end

References

  1. (loop vs while true benchmark: fast-ruby)[https://github.com/fastruby/fast-ruby#loop-vs-while-true-code]