How do I execute this code inside a Thread object?
I want continuous execution, but I a have poor knowledge working with Thread objects. I have a Number class, which receives a number as a parameter.
If the number is even, do something, if odd, do something else, eventually what I am after is a continuous evaluation of the number within this framework of conditions with ‘number’ getting to 1. All elements are to be stored inside an array and querying the array.last to return 1.
class Number
attr_accessor :x
def initialize (number)
@x=[]
if (number % 2 == 0)
@x << number/2
elsif (number % 2 != 0)
@x << (number*3)+1
end
print @x.to_s.concat(" ") // unable to continue
end
I think this is what you are trying to do: