Am 13.02.2014 19:29, schrieb Jaimin Pandya:
> Jess Gabriel y Galn wrote in post #1136295:
>> On Tue, Feb 11, 2014 at 11:20 AM, Jaimin Pandya <lists / ruby-forum.com>
>> wrote:
>>>
>>>         puts x
>>>         end
>>>        x = x + 1
>>>        end
>>>
>>> But this solution of program is wrong.
>>>
>>> So How to solve this program? Please help me on this.
>>
>> What you need to do is to change the 10 in your first program by a
>> number entered by the user. So look into Kernel#gets
>> (http://ruby-doc.org/core-2.1.0/Kernel.html#method-i-gets) and how to
>> convert what the user enters into a number String#to_i
>> (http://ruby-doc.org/core-2.1.0/String.html#method-i-to_i), and you
>> need a second variable to store this number and check x against it.
>>
>> Hope this gets you in the right direction,
>>
>> Jesus.
> 
> I solved the program by following :
> 
> x = 0
> y = gets(10)
> while x <= y.to_i
>   puts x
>   x = x + 1
>   end
> 
> Is this program correct? Could you please tell me?

Did you *try* whether it works?

Answer: Yes (as long as the number does not have more than 10 digits).

And instead of while I would use e.g. Integer#upto.

Regards,
Marcus


-- 
GitHub: https://github.com/stomar/
PGP:    0x6B3A101A