Adım Adım Ruby -5

Kategori (Ruby) Yazar (YaMTaR) Tarih : 16-07-2007

Etiketler : , , , , ,

Vay be Adım Adım Ruby 1. 2. 3. 4. 5 oldu 🙂 

While

def gerisayim(n)
while n > 0
puts n
n = n - 1
end
puts "bittii!"
end

gerisayim(5)
^D

5

4

3

2

1

bittii!

########################################

def karisik(n)

while n != 1
puts n
if n % 2 == 0 # n çift
n = n / 2
else          # n tek
n = n*3 + 1
end
end
end

karisik(9)
^D
9
28
14
7
22
11
34
17
52
26
13
40
20
10
5
16
8
4
2

########################################
i = 1
while i <= 6
print 2 * i
print "   "
i = i + 1
end
puts
^D

2 4 6 8 10 12

 
 
 


Yorum yaz