Example program multiple.rb
x = 1;
#Example 1 - Multiplication using 10.times;puts "From 1 to 10 Multiplication of 5";
10.times do
a = x*5;
puts a;
x = x+1;
end;
#Example 2 - Loop using upto;
puts "From 10 to 20 Multiplication of 5";
1.upto(10) do
a = x*5;
puts a;
x = x+1;
end;
puts "Arrays"
#Example 3 - Arrays list all elements;
arrayA = [1,2,3,4,5];
arrayA.each {|y| puts y};
puts "Array & Strings"
arrayB = [1,2,"One","Two","Three"];
arrayB.each {|y| puts y};
#Example 4 - List the program line by Line;
File.open("d:\multiply.rb").each { |line| puts line }
No comments:
Post a Comment