Write a Ruby program that uses iterator to find out the length of a string.
iterator.rb
print("Enter string:\n")
str = gets
i=0
str.each_char do |c|
i+=1
end
print("Length of given string is ",i-1)
INPUT
Enter string:
hello rise
OUTPUT
Length of given string is 10
iterator.rb
print("Enter string:\n")
str = gets
i=0
str.each_char do |c|
i+=1
end
print("Length of given string is ",i-1)
INPUT
Enter string:
hello rise
OUTPUT
Length of given string is 10