Reputation: 35
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
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