Loop is an group of lines of code executed for multiple times.

Loops in any language used in following use cases.

  • Execute code with number of times
  • Run code with range of values
  • Execute the code until user stops code execution based on some condition

Ruby provides multiple following loop types.

  • While loop
  • while modifier
  • until condtional statement
  • each method
  • Times Loop
  • Range Loop
  • Stopping loop with break
  • Upto loop
  • skip execution with next