i have tried to keep this as simple as possible in order to demonstrate my confusion - i have looked at this for too long now and i really dont understand how this for loop works - sorry for the example length.
xml code:
<?xml version=“1.0” encoding=“iso-8859-1”?>
<root>
<node1>First node value</node1>
</root>
action script (ignoring the xml load part) :
function showNodes(node) {
trace("NODE = " + node);
for(var child = node.firstChild; child != null; child = child.nextSibling) {
trace("Node First Child = " + node.firstChild);
trace("child next sibling = " + child.nextSibling);
showNodes(child);
}
trace("xxxxxxxxxxxxxxxxxxxxxxxx " + node.nodeName + " " + node.nodeValue + " " + node.nodeType);
trace("yyyyyyyyyyyyyyyyyyyyyyyy " + child);
}
output:
NODE = <?xml version=“1.0” encoding=“iso-8859-1”?><root><node1>First node value</node1></root>
Node First Child = <root><node1>First node value</node1></root>
child next sibling = null
NODE = <root><node1>First node value</node1></root>
Node First Child = <node1>First node value</node1>
child next sibling = null
NODE = <node1>First node value</node1>
Node First Child = First node value
child next sibling = null
NODE = First node value
xxxxxxxxxxxxxxxxxxxxxxxx null First node value 3
yyyyyyyyyyyyyyyyyyyyyyyy null
xxxxxxxxxxxxxxxxxxxxxxxx node1 null 1
yyyyyyyyyyyyyyyyyyyyyyyy null
xxxxxxxxxxxxxxxxxxxxxxxx root null 1
yyyyyyyyyyyyyyyyyyyyyyyy null
xxxxxxxxxxxxxxxxxxxxxxxx null null 1
yyyyyyyyyyyyyyyyyyyyyyyy null
i can fully see how things work up until i hit the FOR LOOP EVALUATION:
child !=null
at that point the loop is broken and the trace statements with xxxxx and yyyy come into play but why is there 4 lots of x and y traces?
if the loop is broken and child = null which it does why does the statement carry on 4 more times - should it not just return?
i understand that the update part of the for loop will execute only at the end of the loop but this still does not show why it should carry on like this?
seriously grateful for any help as its driving me nuts
thank you very much in advance