I have a variable x which is set to 10. And I want to write a while loop that increments that. I know you can easily just use a for-loop for this, but easy isn't fun. The code I have is:
def add(a)
g = a + 1
puts g
end
def loop(d)
x = 0
while x <= 4
x += 1
add(d)
end
end
loop(9)
When ran I get 9, four times. How can I get this code to have an output of 9, 10, 11, 12?
xwas never set to10, what contradicts the preface,) that there is no way to fix it save for completely rewrite from the scratch after reading a book on ruby language.xis set to0, not10and your code outputs10four times, not9. Please fix either your code or your question.arrayof numbers 9 to 12 ?