0xr3d0c
0xr3d0c

Reputation: 35

times iterating does not work

I am trying to iterate times with a variable. Why does the variable a not count up?

a=0
pre="a"
until a > 10 do
 a.times print pre
 a +=1
end

Upvotes: 0

Views: 43

Answers (2)

Pete
Pete

Reputation: 2246

It's a little hard to tell from the code, but is the idea that the prepended text (pre) gets printed incrementally more times after each loop? E.g like:

a
aa
aaa
# etc...

You can achieve that with:

10.times do |i|
  i.times print pre
end

Upvotes: -1

Alexander Kireyev
Alexander Kireyev

Reputation: 10825

Should be a.times { print pre }

Upvotes: 4

Related Questions