From: "List.rb" Date: 2009-02-25T00:53:18+09:00 Subject: Re: Error in While Loop On Feb 24, 2009, at 5:57 AM, Naresh Ramaswamy wrote: > Following is my Ruby Code Wherein I am reading an XML file. > I am afraid why my loop is not getting incremented for value of i. > Attached is the XML file for your referance. > > ******************************** > require 'rexml/document' > require 'rio' > include REXML > > $doc = Document.new File.new("script_data.xml") > > $TXN = XPath.match($doc, "//TXN[@value]") > > $i = 0 > > def check > @a = $TXN.size > while $i <= @a #|| $TXN[@i] != 0 do > loop_1 > @b = $TXN[$i].size > @j=1 > while @j <= @b || $TXN[$i][@j] != nil do > loop_2 > @c = $TXN[$i][@j].size > @k=1 > while @k <= @c || $TXN[$i][@j][@k] != nil do > loop_3 > @k +=2; > end > @j +=2; @k = 1; > end > $i +=1; > end > end > > def loop_1 > puts $TXN[$i] > puts "AT LOOP 1" > end > > def loop_2 > p $TXN[$i][@j] > p "value of i #{$i}, j is #{@j}" > puts "AT LOOP 2" > end > > def loop_3 > puts $TXN[$i][@j][@k] > p "value of i #{$i}, j is #{@j}, k is #{@k}" > puts "AT LOOP 3" > end > > check > **************************************** > > regards, > Naresh > > Attachments: > http://www.ruby-forum.com/attachment/3337/script_data.xml > > -- > Posted via http://www.ruby-forum.com/. > Doesn't File.new create a new file? Cant recall off hand..