From: Robert Klemme Date: 2012-11-22T17:01:39+09:00 Subject: Re: how to increase variable inside the while loop On Wed, Nov 21, 2012 at 11:36 PM, Ferdous ara wrote: > Hi, my question might be confusing as its hard for me to make it clear, Chances are that if you understand what you want the solution will come much easier. :-) > what i want is , something like bellow > > $i = 1 > $num = linecount.to_i + 1 > #$faulty_count = 0 > while $i < $num do > current-#{i} = current_result["#{server_name}-#$i"]["usable"] > > puts current-#{i} -------------- > $i +=1 > end > Basically , > i want to store value of current_result["#{servername}-#$i"]["usable"] > in to a variable (incremental variable ) As others have said: store in an Array. I don't know what current_result refers to but it looks like something like this could work: current_first = linecount.times.map {|i| current_result["#{server_name}-#{i + 1}"]["usable"]} > So after this, i wanted to do like this > > current-#{i} == current-#{j} Assuming we have current_first and current_second then you could just do current_first == current_second Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/