A loop is a group of lines of code executed for multiple times.
Loops in any language used in the following use cases.
- Execute code with a number of times
- Run code with a range of values
- Execute the code until the user stops code execution based on some condition
Ruby provides multiple following loop types.
- While loop
- while modifier
- until conditional statement
- each method
- Times Loop
- Range Loop
- Stopping loop with break
- Upto loop
- skip execution with next