My Looping codes in “Ruby”


As i told already, my bro., gave some task in looping, I tried out that tasks,using looping concept in ruby language. The codes are here,

Q1-1: Print the nos from 1 to 1000 in new lines

The “Ruby” way


for i in 1..1000 do
puts i
end

Q1-2: Print the nos from 1 to 1000 using ‘tab’ or/and ‘single’ spaces


for i in 1..1000 do
 print i, " "
 end

Q1-3: Print the nos from 1 to 50 wihtout any spaces,tab,new line.

i.w like 1234….484950


for i in 1..1000 do
print i
end

Q2-1: Print the alphabets from A to Z and a to z


for i in "A".."Z" do
print i
end

for a to z:


for i in "a".."z" do
print i, " "
end

Q2-2: Get any name from user and store it in array variable. Print each
character from that name using loop.
Q2-3: Get 2 names from the user and split those 2 strings into an individual chars and print it like
combination of both names. eg  : 1.Arul 2.Suresh outputs: ASruulesh & SAurruelsh
I’m still trying to get output for the above qus.,

 

Q3: Print ‘Hello World’ for infinite times using while loop.


i=9
while i=0
puts "Hello World"
end

I ve to finish all those qus., I’ll 

Advertisements

One thought on “My Looping codes in “Ruby”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s