Check out example codes for "rails loop". It will help you in understanding the concepts better.

Code Example 1

while $i < $num  do
   puts("Inside the loop i = #$i" )
   $i +=1
end

Code Example 2

for element in array do
  element.do_stuff
end

Code Example 3

for i in 0..2 do 
  print(i)
end

# => 0
# => 1
# => 2

Learn ReactJs, React Native from akashmittal.com