while ruby code example
Example 1: for loop ruby
# You can use an each to mimic the functionality of a for loop
(0..5).each do |i|
puts "Inside loop i = #{i}"
# put your code for loop here
end
# outputs
# Inside loop i = 0
# Inside loop i = 1
# Inside loop i = 2
# Inside loop i = 3
# Inside loop i = 4
# Inside loop i = 5
Example 2: rails loop
while $i < $num do
puts("Inside the loop i = #$i" )
$i +=1
end