How to write while loop in ruby?
In Ruby, a while
loop is used to repeatedly execute a block of code as long as a specified condition evaluates to true
.
Syntax:
while condition
# Code to execute
end
Example:
users = [ "Sandeep", "Virat", "John" ]
index = 0
while index < users.length()
puts "Hello #{users[index]}"
index += 1
end
Output:
