In Ruby, there are several ways to create loops, but the two most common are the while
loop and the for
loop.
main.rb57 chars7 lines
In the example above, we initiated a variable i
and created a while loop that loops until i
is less than 10. During each iteration, we output the current value of i
and increment it by one.
main.rb38 chars5 lines
In the example above, we used a for
loop to iterate over a range of numbers from 0 to 9 (inclusive). During each iteration, we output the current value of i
.
Both loops can be used to perform tasks repeatedly until a certain condition is met. The choice of which loop to use will depend on the specific task that you are trying to perform.
gistlibby LogSnag