Ruby - Statement loop command

Introduction

The loop command does not evaluate a test condition to determine whether to continue looping.

To break out of the loop, you have to explicitly use the break keyword:

Demo

i=0 
arr= [1,2,3,4,5] #  w w w  . j  a  v  a  2 s.c  om
loop do 
    puts(arr[i]) 
    i+=1 
    if (i == arr.length) then  
       break  
    end 
end 

i=0 
arr= [1,2,3,4,5] 
loop { 
    puts(arr[i]) 
    i+=1 
    if (i == arr.length) then  
       break  
    end 
}

Result