Ruby program to Calculate the factorial of given number

In this Ruby example to calculate factorial of a number we are using while loop 

puts "Enter the number"
num=gets.chomp.to_i

i = 1
fact = 1

while i <= num  #implementation of while loop
    fact *= i
    i += 1
end

puts "The factorial of #{num} is #{fact}"

 

Output

Enter the number
 5
The factorial of 5 is 120