In js at least, that is actually alowed. for(var1=x,var2=y,...;condition;step){ Have a great day, Alex New email address: mehgcap@xxxxxxxxx----- Original Message ----- From: "black ares" <matematicianu2003@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx> Sent: Wednesday, October 07, 2009 2:03 AM Subject: Re: for loop being skipped!
the second has even a sintax error I guess. He try to put multiple conditions there, but He separe them by ;. As I remember they must separed by ,----- Original Message ----- From: "qubit" <lauraeaves@xxxxxxxxx>To: <programmingblind@xxxxxxxxxxxxx> Sent: Wednesday, October 07, 2009 2:17 AM Subject: Re: for loop being skipped!Look again at your first loop. You are comparing idx, which is nonzero, to 0 which will always give you false, so the loop will never execute. It's likea while loop with a null condition.I didn't look at the second loop but I am guessing it does the same type ofthing. Just mentally trace the flow and it's not hard to see. --le----- Original Message ----- From: "Alex Hall" <mehgcap@xxxxxxxxx>To: <programmingblind@xxxxxxxxxxxxx> Sent: Tuesday, October 06, 2009 5:44 PM Subject: for loop being skipped! Hi all, I have a very long program in javascript that gets a bunch of stats functions on a list (or two lists) of numbers. Currently I am trying to allow for frequencies, so a user could type 1 2 2 2 3 or just 1 2f3 3 to be the same thing; f is frequency and means to repeat the number before the f as many times as the number after. "str" is my string in the code segment below. The idea is to find the first f in the string and get its index (the idx variable), then start there and go backwards until I find a space; once I hit a space, I can get the characters between it and the index of f, and that is the number to be repeated. I then do the same thing, but going forward from the f index, to see how many times I should repeat the number. However, neither for loop is running!! I have never seen a code segment skipped before, unless it is in a conditional statement (which is not the case here). I have the whole thing in a try/catch (not shown), but that is not picking up any errors and the alert to tell me the start and stop variables is working, except both equal 0. If you want to test it, just initialize str to something like 1 2f3 4 and see what happens. Again, this is javascript. //get the first index of "f" var idx=str.indexOf("f"); var start=0; var stop=0; var i=idx; //move backward from there until we hit a space alert("about to loop: "+i+", "+idx); for(i=idx;i==0;i--){ alert("first loop"); //to see if it is ever entered if(str.charAt(i)==" " || i==0){ //space found or start of list, so end alert("getting start"); start=i; break; } } //now do the same thing, but moving forward for(i=idx,l1=str.length;i<l1;i++){ if(str.charAt(i)==" "){ stop=i; break; } } alert(start+" to "+stop); __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind __________ View the list's information and change your settings at //www.freelists.org/list/programmingblind__________View the list's information and change your settings at //www.freelists.org/list/programmingblind
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind