M
mochipon
Guest
Let's say I have a piece of code like this:
Is the number of iterations of the for loop fixed at the time it's started (when list_items is = 5)? If I increase the value of list_items to 7 or 8 before the loop has reached its fifth iteration, will it go on to 7 or 8, if the condition was met and list_items is now higher than when the loop was started? In other words, will the variable loop counter always be 5 at the end of the thing, or can it go higher?
If so, can a while loop do something else? How can I dynamically extend the number of loops based on conditions met inside the loop? I'm kind of suspecting it's fixed, but maybe I'm mistaken and there's some other error inside my code. Do I have to use something like a recursive call of a script instead?
Code:
list_items = 5;
loop_counter = 0;
for (var i = 0; i < list_items; i++) {
if (condition so and so) { list_items++; }
if (condition this and that) { list_items++; }
loop_counter++;
}
If so, can a while loop do something else? How can I dynamically extend the number of loops based on conditions met inside the loop? I'm kind of suspecting it's fixed, but maybe I'm mistaken and there's some other error inside my code. Do I have to use something like a recursive call of a script instead?