#display An Array
the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
#OR
for number in the_count
puts "This is count #{number}"
end
#OR
the_count.each do |number|
puts "no. are #{number}"
end
#OR
fruits.each do |fruit|
puts "A fruit of type: #{fruit}"
end
#OR
change.each {|i| puts "I got #{i}" }
# OR
fruits.each {|i| puts " list of ::#{i}" }
OUTPUT:
This is count 1
This is count 2
This is count 3
This is count 4
This is count 5
no. are 1
no. are 2
no. are 3
no. are 4
no. are 5
A fruit of type: apples
A fruit of type: oranges
A fruit of type: pears
A fruit of type: apricots
I got 1
I got pennies
I got 2
I got dimes
I got 3
I got quarters
list of ::apples
list of ::oranges
list of ::pears
list of ::apricots
the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
#OR
for number in the_count
puts "This is count #{number}"
end
#OR
the_count.each do |number|
puts "no. are #{number}"
end
#OR
fruits.each do |fruit|
puts "A fruit of type: #{fruit}"
end
#OR
change.each {|i| puts "I got #{i}" }
# OR
fruits.each {|i| puts " list of ::#{i}" }
OUTPUT:
This is count 1
This is count 2
This is count 3
This is count 4
This is count 5
no. are 1
no. are 2
no. are 3
no. are 4
no. are 5
A fruit of type: apples
A fruit of type: oranges
A fruit of type: pears
A fruit of type: apricots
I got 1
I got pennies
I got 2
I got dimes
I got 3
I got quarters
list of ::apples
list of ::oranges
list of ::pears
list of ::apricots
No comments:
Post a Comment
if you have any query regarding geek languages,
email on arora.ratul@gmail.com