ruby for loop
for i in 0..2 do
print(i)
end
# => 0
# => 1
# => 2
ruby for loop
for element in array do
element.do_stuff
end
ruby for loop
# 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
ruby for
for counter in 1..5
puts "iteration #{counter}"
end
#=> iteration 1
#=> iteration 2
#=> iteration 3
#=> iteration 4
#=> iteration 5
rails loop
while $i < $num do
puts("Inside the loop i = #$i" )
$i +=1
end
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us