473,480 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

'for' loop being killed before it's finished.

bugboy
160 New Member
Hi I'm trying to build tree type lists where each row in the list has several cells (columns). My code will render the first list ok then stops. The first 'for' statement should be moving to build the second list, but the loop is killed. The 'list', 'row' and 'cell' constructors are not shown.

Any idea what's killing the initial iteration.. is it the recursion in getChildren()?

Thanks for you help!

Expand|Select|Wrap|Line Numbers
  1. function  getlist()
  2.     { 
  3.     this.list = arguments[0].split(",");
  4.     this.render = function()
  5.         {
  6.         document.getElementById('workspace').innerHTML="";
  7.         for(x in this.list)
  8.             { 
  9.             var listid = this.list[x];
  10.             var rootid = list[listid].root;
  11.             document.getElementById('workspace').innerHTML += list[listid].html;
  12.             list[listid].resize();
  13.             resize('workspace', 'list.'+listid);
  14.             document.getElementById('list.'+listid).innerHTML += row[rootid].html;//render the root's html
  15.             getcells(rootid, 'row.'+rootid);
  16.             getChildren(rootid);
  17.             }
  18.         }
  19.     }
  20.  
  21. function getChildren(rowid)
  22.     {
  23.     for(n in row[rowid].children)
  24.         { 
  25.         var child = row[rowid].children[n];
  26.         document.getElementById('children.'+rowid).innerHTML += row[child].html;//add the child row html the the child container
  27.         getcells(child, 'row.'+child);
  28.         getChildren(child);//then get the child row's children
  29.         }
  30.     } 
  31.  
  32. function getcells(rowid, target)
  33.      {
  34.     for(y in row[rowid].cell)
  35.         { 
  36.         var cellid = row[rowid].cell[y];
  37.         document.getElementById(target).innerHTML += cell[cellid].html;//then add the cells to that child row html
  38.         }
  39.     }
Mar 29 '10 #1
10 1922
RamananKalirajan
608 Contributor
Hi bugboy,
Use try and catch block for the functions. Then you will know the source of the bug. Or you have to use alert and chek. Moreover in getChildren() you havent used return, since the function is a recursive() it will be expecting a return.

sample Code:

Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3.    //your code goes here.
  4. }
  5. catch(e)
  6. {
  7.  alert(e.message);
  8. }
Thanks and Regards
Ramanan Kalirajan
Mar 29 '10 #2
phvfl
173 Recognized Expert New Member
Is the list variable on line 10 a global? I can't see it declared anywhere.
Mar 29 '10 #3
bugboy
160 New Member
'list' 'row' and 'cell' are all objects, i haven't shown their constructors.

'getChildren' and 'getCells' both write to the target element in the document so a return isn't needed as far as i know.
Mar 29 '10 #4
bugboy
160 New Member
If i remove the call to it's self inside getChildren it works fine rendering both lists - except it won't get the children of the children so the tree/list only renders two levels deep. If i leave it in place the first tree/list renders fine with multiple levels but then the second list doesn't render at all, it's as if the initial 'for' loop in getList is just forgotten once recursion starts.
Mar 29 '10 #5
RamananKalirajan
608 Contributor
When are you stopping the recursive function?

Thanks and Regards
Ramanan Kalirajan
Mar 29 '10 #6
Dormilich
8,658 Recognized Expert Moderator Expert
note: be cautious when using a for … in loop, it does not only fetch the numeric members.

what’s this? (line #26): row[child].html
Mar 29 '10 #7
bugboy
160 New Member
The recursive function is called inside the for loop so it is only called once for each subchild, when there aren't any subchildren the for loop stops.

Sorry i'm not sure what you mean by not only numeric members.?

(line #26): row[child].html is just an html string being retrieved from the row object.
Mar 29 '10 #8
bugboy
160 New Member
I've replaced the getChild for ...in loop with a while and it appears to work!

What was the for ..in loop doing wrong?

Expand|Select|Wrap|Line Numbers
  1. function getChildren(rowid)
  2.     {
  3.     var x = 0;
  4.     while(row[rowid].children[x])
  5.         { 
  6.         var child = row[rowid].children[x];
  7.         document.getElementById('children.'+rowid).innerHTML += row[child].html;//in the rows children container add the child row html
  8.         getcells(child, 'row.'+child);
  9.         getChildren(child);//then get the child row's children
  10.         x=x+1;
  11.         }
}
Mar 29 '10 #9
Dormilich
8,658 Recognized Expert Moderator Expert
@bugboy
numeric members: list[0], list[1], etc. for … in also loops over custom members (anything that is not a numbered member)
Mar 29 '10 #10
bugboy
160 New Member
Ahh right, Thanks for your help guys!

I'm not sure what the problem was, my arrays only have successive numeric members.. hard to pick the best answer..
Mar 29 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

77
5617
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a...
39
789
by: jabailo | last post by:
I am looping through a text file, and with each row, I launch a web service, asynchronously. Before I move on to the next step in the process, I want to make sure that all the web services have...
3
2931
by: Richard Cavell | last post by:
I have a recursive function like this: void MyFunction(int i) { i++; // do something with i if (we're not finished) MyFunction(i); } I keep count of how far nested we are with i. Now, it...
6
7594
by: F-13 | last post by:
I'm working on a BOM in Access 200 from an example downloaded from from the web. The sample database contains three tables, Assemblies (the list of items needed to assemble any assembly),...
11
6911
by: ryan | last post by:
Hi, I've omitted a large chunk of the code for clarity but the loop below is how I'm calling a delegate function asynchronously. After I start the each call I'm incrementing a counter and then...
5
10559
by: eb65 | last post by:
I have a need to write a Windows Service application in VB.Net that needs to continuously do some processing, wait ten minutes, then repeat. What is a good approach to coding this type of thing?...
5
6777
by: mturner64 | last post by:
Good day. I am working on a program that will allow a user to enter an undefined series of numbers and enter -99 when finished. The program should output the Greatest and Least of the series...
15
2337
by: Steve | last post by:
I am having problems getting values out of an array. The array is set as a global array and values are pushed into it as they are read from a JSON file using a "for loop". When the "for loop" is...
9
8771
by: saravanan82 | last post by:
Hi All, I tried to execute follwoing program, which got killed by the OS. #include<stdlib.h> main() { while(1) { char *c=(char*)malloc(10000); } }
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5342
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.