Does anybody here know javascript? Odd function problem

Status
Not open for further replies.

Vigilante

Posts: 1,634   +0
Hey, I usually have other forums for programming, but since I like it here, I figured I'd give my fellow members a shot at it. Let me summarize my code, see if you can tell me why I'm having the issue. Here is a mock up, simplistic java function:

<script>
function test() {
var somevar;
var somevar2;
//other assignments

for ( the main for loop ) {

// all kinda stuff in for loop

}

// NOTHING HERE EXECUTES!!

}
</script>

Can anybody tell me why I cannot execute any code after the for loop, inside the function? Or why that might be?
Note that in the for loop, I use NO break or continue statements. In the for loop I have a while loop and one IF statement. That's it. But when the FOR loop ends, I can't do anything else in code. What's up with that?
I know the for loop and sub code works just fine, as I've monitored it and the output is perfect. But when the loop comes to an end, apparently so does all other code in the function.

Any ideas?
 
Your code seems fine, but is anything actually calling the function?

Is this code in the HEAD or BODY of the page? It doesn't matter too much, but I personally put it in the head. If it is in the body and there are no parameters, you don't really need the function test() { and last }. It should just execute. But if you prefer to have that, call the function. Easiest way would be just before the close script tag, put on a new line test(); unless you want it called at a specific point.

Hope that helps :)
 
I finally found the problem and it had to do with an inner WHILE loop, my counter was going out of bounds and throwing an error on the while condition check.

IE actually helped with this, as it gives you the java error, which I never noticed because I was using Avant.

Oh well, the issue is resolved. Thanks for the thought.
 
Status
Not open for further replies.
Back