From: sto.mar@... Date: 2012-11-23T05:24:54+09:00 Subject: Re: how to increase variable inside the while loop Am 22.11.2012 09:01, schrieb Robert Klemme: > 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 You have no reason to make `i' and `num' global variables, so don't. >> 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"]} Probably easier to grasp for a beginner: current_first = [] linecount.times do |i| current_first << current_result["#{server_name}-#{i + 1}"]["usable"] end >> 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 --